主题:[讨论]排列组合问题
完善程序试题,想了一整天,没有看出来什么意思,请高手给于指点啊!
键盘输入N,屏幕输出N个1和N个2组成的构成3跳(相邻两数不同为1跳)的排列方式。
INPUT N: DIM A(N * 2)
FOR I = 1 TO N : A(I) = 1: A(N + I) = 2 :NEXT I
DO WHILE ___________
J = N * 2
DO WHILE ___________
J = J - 1
LOOP
________________
DO WHILE ______________
K = K - 1
LOOP
SWAP A(J - 1), A(K)
FOR P = J TO N * 2 - 1
FOR Q = P + 1 TO N * 2
IF _______________ THEN SWAP A(P), A(Q)
NEXT Q, P
S = 0
FOR L = 1 TO N * 2 - 1
IF A(L) <> A(L + 1) THEN S = S + 1
IF S>3 THEN EXIT FOR
NEXT L
IF ______________THEN
FOR L = 1 TO N * 2
PRINT USING "#"; A(L);
NEXT L : PRINT
END IF
LOOP
键盘输入N,屏幕输出N个1和N个2组成的构成3跳(相邻两数不同为1跳)的排列方式。
INPUT N: DIM A(N * 2)
FOR I = 1 TO N : A(I) = 1: A(N + I) = 2 :NEXT I
DO WHILE ___________
J = N * 2
DO WHILE ___________
J = J - 1
LOOP
________________
DO WHILE ______________
K = K - 1
LOOP
SWAP A(J - 1), A(K)
FOR P = J TO N * 2 - 1
FOR Q = P + 1 TO N * 2
IF _______________ THEN SWAP A(P), A(Q)
NEXT Q, P
S = 0
FOR L = 1 TO N * 2 - 1
IF A(L) <> A(L + 1) THEN S = S + 1
IF S>3 THEN EXIT FOR
NEXT L
IF ______________THEN
FOR L = 1 TO N * 2
PRINT USING "#"; A(L);
NEXT L : PRINT
END IF
LOOP