poj 动态规划DP - 1163 The Triangle
来源:互联网 发布:linux 下的虚拟机 编辑:程序博客网 时间:2024/06/07 07:41
这里有一份DP题目列表点击打开链接,大家想专门刷DP的可以看一下。
这是一道经典的DP题,找出从顶到底和最大的路径和。
我们先记录每个路径点上面的值map[i][j] ,这道题的递推式是
map[i][j] = max(map[i-1][j]+map[i][j],map[i-1][j-1]+map[i][j]);
当然最边缘的路径只有一条,单独考虑。
# include<stdio.h># define MAX 105# define max(x,y)(x>y ? x:y )int n;int map[MAX][MAX];void DP(){int i,j,maxd = 0;for(i=1;i<=n;i++){for(j=1;j<=i;j++){if(j==1)map[i][j] += map[i-1][j];else if(j==i)map[i][j]+= map[i-1][j-1];else map[i][j] = max(map[i-1][j]+map[i][j],map[i-1][j-1]+map[i][j]);}}for(i=1;i<=n;i++) maxd= max(maxd,map[n][i]);printf("%d\n",maxd);}int main(){int i,j;scanf("%d",&n);for(i=1;i<=n;i++){for(j=1;j<=i;j++){scanf("%d",&map[i][j]);}}DP();return 0;}
0 0
- poj 动态规划DP - 1163 The Triangle
- poj-1163-The Triangle-动态规划dp
- POJ-1163-The Triangle-动态规划
- poj 1163 The Triangle 线性动态规划
- poj 1163 The Triangle (动态规划)
- POJ 1163 The Triangle (动态规划)
- poj 1163 The Triangle 动态规划
- POJ 1163:The Triangle(动态规划)
- POJ 1163 The Triangle & POJ 3176 Cow Bowling(DP动态规划)
- poj 1163 The Triangle (动态规划入门题)
- 动态规划入门-POJ 1163-The Triangle(数字三角形)
- POJ-1163(The Triangle)动态规划基础题
- poj 1163-小白算法练习 The Triangle 动态规划
- POJ 1163 The Triangle数塔 动态规划
- 1163 The Triangle 动态规划
- POJ 1163 The Triangle (DP)
- POJ 1163 The Triangle【DP】
- poj 1163 The Triangle【dp】
- Hadoop安装前SSH无密码登录配置
- RMI简单教程
- Unable to find the ncurses libraries的解决办法
- poj--1961--KMP
- 视讯稳定对接出现的问题
- poj 动态规划DP - 1163 The Triangle
- Opening Ceremony
- poj 2019 Cornfields
- Hdoj 5210 Delete 【水】
- mongodb
- 使用oscache提高程序性能
- Vimperator
- arch - pacman 使用方法
- ZOJ Problem Set - 3878||Convert QWERTY to Dvorak