Topic 1205:n Stair Stairs upstairs problem
time limit:1 seconds
Memory limit:128 MB
Special question: No
submitted:2817
Resolution:1073
-
Title Description:
-
N-Step stairs upstairs problem: one can walk two or one order, ask how many kinds of way upstairs. (Non-recursive requirements apply)
-
Input:
-
The input includes an integer N, (1<=n<90).
-
Output:
-
There may be multiple sets of test data, for each set of data,
The number of ways to go upstairs when the stair order is n.
-
Sample input:
-
4
-
Sample output:
-
5
Basic ideas:
Go to the nth order may be from the first step to the n-1, or from the n-2 order to go two steps,
Set F (n) as the number of walks to the n order, then the state transfer equation is
F (n) =f (n-1) +f (n-2).
#include <stdio.h> #include <string.h>long long f[100];int main (int argc, char *argv[]) { int n; while (~SCANF ("%d", &n)) { memset (f,0,sizeof (f)); F[0]=f[1]=1; for (int i=2;i<=n;++i) f[i]=f[i-1]+f[i-2]; printf ("%lld\n", F[n]); } return 0;}
Nine degrees OJ 1205 N-Step stairs Upstairs problem (DP)