您的位置:首页 > 其它

动态规划(DP)

2014-11-13 15:24 120 查看
动态规划,Dynamic programming,不是Dynamic planning ...

将问题分成若干子问题,前面的解为后面的解所用,注意逆向推倒,找出递推公式,经典的01背包问题,晚点实现一下,这里搞一个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?

public class Solution {
public int climbStairs(int n) {
int steps[] = new int[n + 1];
for(int i = 0; i <= n; i++){
if(0 == i || 1 == i)
steps[i] = 1;
else{
steps[i] = steps[i - 1] + steps[i - 2];
}
}
return steps
;
}
}


01背包问题,待写...
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: