1091: The childhood life two or three things (multi-instance test)Time limit:1 Sec Memory limit:128 MB
submit:4299 solved:2457
Submit Status Web Board
Description
Redraiment like to bounce when he was a child, and he likes to jump up and down the stairs.
But at a young age, he can only go one step at a time or jump on two.
There are now a total of N-step, please calculate the redraiment from the No. 0 order to the nth order altogether several walks. Input
Input includes multiple sets of data.
Each set of data includes one row: N (1≤n≤40).
Input ends with 0 Output
The
corresponds to one output for each input. The number of redraiment to which the nth order is reached by the
. Sample Input 1
3
0 Sample Output 1
3
Resolution:
& nbsp; if it is not the master to find the law, I am afraid it is difficult to believe that this is the Fibonacci sequence.
0-----1 1
0------2 2
0------3 3
0------4 5
0------5 8
The
program is as follows:
#include <cstdio>
int main ()
{
int a[1000],t,i;
while ((scanf ("%d", &t) &&t!=0))
{
a[0]=1;
a[1]=2;
for (i=2;i<t;i++)
{
a[i]=a[i-1]+a[i-2];
}
if (t<2)
printf ("1\n");
else
printf ("%d\n", A[i-1]);
return 0;