Home > Back-end >  Climb building c/c address topics (output all details)
Climb building c/c address topics (output all details)

Time:04-01

#include
Int main ()
{
int n;
While (the scanf (" % d ", & amp; N)!=(EOF)
{
Int num [266].
int count=0;
for(int i=1; i<4. I++)
{
Count=0;
Num [count]=I;
N=n - (I);
If (n==0) {
For (int h=0; H<=count; H++) {
Printf (" % d ", num [h]);
}
printf("\n");
}
If (n<0 {
break;
}
count++;
For (int j=1; j<4. J++)
{
N=n - j;
Num [count]=j;
If (n==0) {
For (int h=0; H<=count; H++) {
Printf (" % d ", num [h]);
}
printf("\n");
}
If (n<0 {
break;
}
count++;
For (int i1=1; I1 & lt; 4. I1 + +)
{
Num=[count] i1;
N=n - i1.
If (n==0)
{
For (int h=0; H<=count; H++)
{
Printf (" % d ", num [h]);
}
printf("\n");
}
If (n<0 {
break;
}
count++;
For (int m=1; m<4. M++)
{
Num=[count] m;
N=n - m;
If (n==0)
{
For (int h=0; H<=count; H++)
{
Printf (" % d ", num [h]);
}
printf("\n");
}
If (n<0)
{
break;
}
count++;
}
}
}
}
}
return 0;
}
All requirements output
Example: such as input 4 (up to four layers), every time go 1/2/3 three conditions
The output of 1111
112
121
13
211
22
31

CodePudding user response:

CodePudding user response:

Fyi:
//every step can only take one or two steps, first the left foot, and then left, the last step is right, that is to say, even a total want to go further, so, on the 39 steps, how many different kinds of method? 
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
//status in c [0] [I] in the case of a staircase I the last step is left foot on the number of methods, c [I] [1] is the right way,,
//so, because each step on one or two levels, c [I] [0]=c [I - 1] + [1] [2] I - c [1] (for the last step left foot,
//the penultimate step must be right,,,, and recursion, and finally c [39] [1] is to level the 39th and is the right way is the answer,
# include & lt; Stdio. H>
Int c [40] [2];//0 as the left foot, 1 is the right foot,,
Int main () {
int i;
C [0] [0]=c [1] [1]=0;
C [0] [1]=c [1] [0]=1;
For (I=2; I & lt;=39; + + I) {
[I] [0] c=c [I - 1] + [1] [2] I - c [1];
[I] [1] c=c [0] + [I - 1] [2] I - c [0];
}
Printf (" % d \ n ", c [39] [1]).
return 0;
}
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
//go n steps, his previous step is not in the n - 1 level is in the n - 2 level,
//f (n)=f (n - 1) + f (n - 2) simple recursive thought
Int num=0;
Void fun (int n, int step)
{
If (n<0)
return;
If (n==0)
{
If (step % 2==0) num++;
return;
}
Fun (n - 1, step + 1);
Fun (n - 2 step + 1);
}
Void main ()
{
Fun (39, 0).
Printf (" % d ", num);
}
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Int aux (int steps, int CNT)
{
If (steps & lt;=0)
{
If (0==steps & amp; & (CNT & amp; & ! (CNT % 2)))
return 1;
return 0;
}
Return aux (CNT steps - 1, + 1) + aux (steps 2, CNT + 1);
} & lt; br>
The inline int func (steps)
{
Return aux (steps, 0);
}
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
# include & lt; Stdio. H>
Static int trace [40];
Static int count=0;
Void the go (int, int, int);
Int main ()
{
The go (39, 0, 1);
The go (39, 0, 2);
Printf (" count=% d \ n ", count);
}
//
//left: the left steps
//mt: mount_times
//step: the steps of the current movement
//
Void the go (int left, int mt, int step)
{
int i;
If (left & lt; 0) return;
If (left==0) {
if(! (mt % 2) & amp; & (step==1) {
/* used to record the footsteps of xiao Ming, of course, is not only asked us to write down,
for(i=0; iPrintf (" % 3 d ", the trace [I]);
}
printf("\n");
For (I=mt; iTrace [I]=0;
}
*/
count++;
}
return;
}
Trace/mt=step;
Left -=step;
Mt++;
The go (left, mt, 1);
The go (left, mt, 2);
}
  • Related