POJ 1163 The Triangle (数塔)
来源:互联网 发布:男士 羽绒服推荐 知乎 编辑:程序博客网 时间:2024/06/04 20:09
题目大意
- 一个n层的数塔,从第一层走到最后一层,沿途经过的数的最大值
分析
- dp[i][j]表示到达(i , j)时的最大值
状态转方程
dp[i][j] = max(dp[i-1][j-1] , dp[i-1][j]) + a[i][j];
代码
#include <iostream>#include <cstring>using namespace std;const int maxn = 360;int dp[maxn][maxn]; //dp[i][j]表示到达(i,j)时的最大值int a[maxn][maxn];int main(){ int n; while(cin >> n) { for(int i = 1; i <= n; i++) for(int j = 1; j <= i; j++) cin >> a[i][j]; memset(dp , 0 , sizeof(dp)); //dp[i][j] = max(dp[i-1][j-1] , dp[i-1][j]) + a[i][j]; for(int i = 1; i <= n; i++) for(int j = 1; j <= i; j++) dp[i][j] = max(dp[i-1][j-1] , dp[i-1][j]) + a[i][j]; int ans = dp[n][1]; for(int i = 2; i <= n; i++) ans = max(ans , dp[n][i]); cout << ans << endl; } return 0;}
0 0
- POJ 1163 The Triangle (数塔)
- POJ 1163 The Triangle(DP 数塔问题)
- POJ 1163 The Triangle(数塔模型dp)
- POJ 3176-Cow Bowling/POJ 1163-The Triangle(简单DP-数塔)
- POJ 1163 The Triangle数塔 动态规划
- POJ The Triangle (dp数塔)
- The Triangle(数塔)
- The Triangle(POJ-1163)
- The Triangle--poj--1163
- 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 1163 The Triangle
- POJ 1163 The Triangle
- 代理设计模式
- log4j:WARN 警告
- HDU 1556 Color the ball (简单树状数组)
- linux下配置网络
- Xpage重复控件的使用(repeat)
- POJ 1163 The Triangle (数塔)
- 电机飞车现象
- HttpClient4.3 第二次封装
- 基于 DOM 的跨站点脚本编制
- URL的访问
- iOS中assign,copy,retain之间的区别以及weak和strong的区别
- Oracle创建表空间、创建用户以及授权、查看权限
- 【扣丁学堂】月薪1700元退伍兵哥蜕变为月薪万元IT男
- 浅谈Java中的hashcode方法