[LeetCode] Climbing Stairs

http://oj.leetcode.com/submissions/detail/1508385/

最最简单的dp

 1 class Solution {
 2 public:
 3     int flag[1000001] = {0};
 4     int f(int n) {
 5         if (flag[n] != 0) return flag[n];
 6         if (1 == n) {
 7             return 1;
 8         } else if (2 == n) {
 9             return 2;
10         } else {
11             flag[n] = f(n - 1) + f(n - 2) ;
12             return flag[n];
13         }
14     }
15     
16     int climbStairs(int n) {
17         memset(flag,0, 1000001);
18         return f(n);
19     }
20 };

 

posted @ 2013-11-21 13:13  NextLife  阅读(226)  评论(0)    收藏  举报