question link : CCF NOI100003 up the stairs .
Time limit: 1000 ms Space limit: 262144 KB
Topic Description
Stairs have n steps, stairs can be a step up the stairs, can also step two steps. Compile a program to calculate how many different walks are in total.
input
One row, an integer n (1 <= n <= 30), represents the series of steps .
Output
An integer, the number of methods to go.
Sample Input
3
Sample Output
3
Programme 1: Walk three times, one step at a time
Scenario 2: Go first, then two.
Option 3: Go to Level Two first, go again
Data Range Restrictions
Problem Analysis
This is a recursive computation problem, the key is to find the recursive type.
See the reference link.
Program Description
Slightly
Essentials to use functions to encapsulate functional functions as far as possible. The key to recursion problem is recursion type.
Reference link : HDU2041 super Staircase.
The C language Program of 100 minutes:
#include <stdio.h>
typedef unsigned long long ull;
ull Stairs (int n)
{
ull f1=1, f2=2, temp;
if (n = = 0) return
0;
else if (n = = 1) return
1;
else if (n = = 2) return
2;
for (int i=3; i<=n; i++) {
temp = f1 + F2;
f1 = F2;
F2 = temp;
}
return f2;
}
int main (void)
{
int n;
scanf ("%d", &n);
printf ("%lld\n", Stairs (n));
return 0;
}