[LeetCode] Climbing Stairs

You are climbing a stair case. It takes n steps to reach to the top.

Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?

fib数列

 1 class Solution {
 2 public:
 3     int climbStairs(int n) {
 4         // Start typing your C/C++ solution below
 5         // DO NOT write int main() function
 6         long long f[100];
 7         f[0] = 1;
 8         f[1] = 1;
 9         
10         for(int i = 2; i < 100; i++)
11             f[i] = f[i-1] + f[i-2];
12             
13         return f[n]; 
14     }
15 };
posted @ 2012-10-29 14:22  chkkch  阅读(637)  评论(0编辑  收藏  举报