-
Total time limit: 1000ms memory limit: 1000kB
-
-
Describe
-
-
from upstairs to downstairs a total of h steps, each step there are 3 ways to go: Walk 1 steps, walk 2 steps, walk 3 steps. Q. How many options can you get out of and print out a specific plan?
-
-
Input
-
-
number of steps H
-
-
Output
-
-
various ways to go and the total number of solutions
-
-
Sample input
-
-
5
-
-
Sample output
-
-
Plan 1:32
-
-
Plan 2:311
-
-
Plan 3:23
-
-
Plan 4:221
-
-
Plan 5:212
-
-
Plan 6:2,111
-
-
Plan 7:131
-
-
Plan 8:122
-
-
Plan 9:1211
-
-
Plan 10:113
-
-
Plan 11:1121
-
-
Plan 12:1112
-
-
Plan 13:11,111
-
-
Number of Plans:13
-
-
-
-
-
Thought: Because every step of the way is slightly the same, you can use a recursive method.
-
-
Code:
-
1#include <iostream>2 using namespacestd;3 4 inttake[ About];5 intnum =0;//Number of programmes6 voidTry (intIints)7 {8 for(intj=3; J>0; j--)9 {Ten if(i>=j) One { ATake[s] =J; - if(i==j) - { thenum++; -cout<<"Plan"<<num<<":"; - //output sub-scheme - for(intk=1; k<=s; k++) +cout<<Take[k]; -cout<<Endl; + } A Else //not yet to go downstairs atTry (I-j, s+1); - } - - } - } - in intMain () - { to intN; +Cin>>N; - theTry (N,1); * $cout<<"Number of plans:"<<num<<Endl;Panax Notoginseng return 0; -}
Recursion-down stairs