The consensus has been that they must have known before.
Not so, says the BBC.. Apparently it was all in the choreography. The professionals apparently rehearsed seven different endings to get them to their celebrities.
Just before the routine was performed, the choreographer was able to quickly remind the dancers which ending they had to dance - but as professionals they could adapt easily."Hmmm. An awful lot of variables in there. Sounds very complicated even for fantastically skilled professionals. I still think they knew beforehand, even if the celebrities didn't.