poj 3176
来源:互联网 发布:淘宝网抢拍软件 编辑:程序博客网 时间:2024/04/27 17:07
题目链接:http://poj.org/problem?id=3176
大意:
从第一行开始至下找寻一条数值最大的路,要求每次向下只能是该点的下一行的前一列和当前列位置选择
思路:
正常动规即可
动规方程:
dp[i][j] = max(dp[i][j], max(dp[i-1][j] + num[i][j], dp[i-1][j-1] +num[i][j]));
代码:
#include<iostream>#include<cstdio>using namespace std;int dp[360][360];int num[360][360];int main(){ int n; scanf("%d", &n); for(int i = 1; i <= n; i++) { for(int j = 1; j <= i; j++) { scanf("%d", &num[i][j]); } } dp[1][1] = num[1][1]; for(int i = 2; i <= n; i++) { for(int j = 1; j <= n; j++) { dp[i][j] = max(dp[i][j], max(dp[i-1][j] + num[i][j], dp[i-1][j-1] +num[i][j])); } } int ans = 0; for(int i = 1; i<=n; i++) { ans = max(ans, dp[n][i]); } printf("%d\n", ans); return 0;}
0 0
- POJ 3176
- POJ-3176
- POJ 3176
- poj 3176
- poj----3176
- POJ 3176
- poj-3176
- poj-3176
- poj 3176
- poj 3176
- POJ 3176
- poj 3176
- poj 3176
- POJ 3176
- poj 3176
- POJ 3176
- POJ 3176 && 1163
- POJ 3176 COW BOWLING
- Xcode8更新之后模拟器找不到了
- 稀疏矩阵的压缩存储与快速转置 三元组法 类与对象实现
- 使用react native开发ios心得杂记
- 第八周 双色球
- Dijkstra 最短路径
- poj 3176
- QSettings的基本使用详解(一)
- Fast and Accurate Image Upscaling with Super-Resolution Forests
- 使用js实现放大镜的效果
- 带输入的Dialog
- Flask Web开发选型
- RxJava系列三
- C 控制流
- android那些事--混淆的粗暴接触