poj3176--Cow Bowling(dp:数塔问题)
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 14028 | Accepted: 9302 |
Description
7
3 8
8 1 0
2 7 4 4
4 5 2 6 5
Then the other cows traverse the triangle starting from its tip and moving "down" to one of the two diagonally adjacent cows until the "bottom" row is reached. The cow's score is the sum of the numbers of the cows visited along the way. The cow with the highest
score wins that frame.
Given a triangle with N (1 <= N <= 350) rows, determine the highest possible sum achievable.
Input
Lines 2..N+1: Line i+1 contains i space-separated integers that represent row i of the triangle.
Output
Sample Input
5
7
3 8
8 1 0
2 7 4 4
4 5 2 6 5
Sample Output
30
Hint
7
*
3 8
*
8 1 0
*
2 7 4 4
*
4 5 2 6 5
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int dp[400][400] ;
int main()
{
int n , i , j , max1 ;
while(scanf("%d", &n) !=EOF)
{
max1 = 0 ;
memset(dp,0,sizeof(dp));
for(i = 1 ; i <= n ; i++)
for(j = 1 ; j <= i ; j++)
scanf("%d", &dp[i][j]);
for(i = 1 ; i <= n ; i++)
for(j = 1 ; j <= i ; j++)
dp[i][j] = max( dp[i-1][j-1],dp[i-1][j] ) + dp[i][j] ;
for(i = 1 ; i <= n ; i++)
max1 = max(max1,dp[n][i]);
printf("%d\n", max1);
}
return 0;
}
poj3176--Cow Bowling(dp:数塔问题)的更多相关文章
- poj-3176 Cow Bowling &&poj-1163 The Triangle && hihocoder #1037 : 数字三角形 (基础dp)
经典的数塔模型. 动态转移方程: dp[i][j]=max(dp[i+1][j],dp[i+1][j+1])+p[i][j]; #include <iostream> #include ...
- POJ3176——Cow Bowling(动态规划)
Cow Bowling DescriptionThe cows don't use actual bowling balls when they go bowling. They each take ...
- POJ 3176 Cow Bowling(dp)
POJ 3176 Cow Bowling 题目简化即为从一个三角形数列的顶端沿对角线走到底端,所取得的和最大值 7 * 3 8 * 8 1 0 * 2 7 4 4 * 4 5 2 6 5 该走法即为最 ...
- HDU2084基础DP数塔
数塔 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submissi ...
- UVA 116 Unidirectional TSP(dp + 数塔问题)
Unidirectional TSP Background Problems that require minimum paths through some domain appear in ma ...
- POJ3176 Cow Bowling 2017-06-29 14:33 23人阅读 评论(0) 收藏
Cow Bowling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19173 Accepted: 12734 Des ...
- Poj3176 Cow Bowling (动态规划 数字三角形)
Description The cows don't use actual bowling balls when they go bowling. They each take a number (i ...
- HDU 1176免费馅饼 DP数塔问题转化
L - 免费馅饼 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Sta ...
- DP~数塔(hrbustoj1004)
aaarticlea/bmp;base64,iVBORw0KGgoAAAANSUhEUgAAAtQAAAPgCAYAAAASsev/AAAgAElEQVR4nOzdf4w0x33n9/4rQP4L8s
随机推荐
- 14.8.1 Enabling File Formats
14.8 InnoDB File-Format Management 14.8.1 Enabling File Formats 14.8.2 Verifying File Format Compati ...
- Android高手进阶——Adapter深入理解与优化
Android高手进阶--Adapter深入理解与优化 通常是针对包括多个元素的View,如ListView,GridView.ExpandableListview,的时候我们是给其设置一个Adapt ...
- LeetCode--Best Time to Buy and Sell Stock (贪心策略 or 动态规划)
Best Time to Buy and Sell Stock Total Accepted: 14044 Total Submissions: 45572My Submissions Say you ...
- java.util.Queue用法
队列是一种特殊的线性表,它只允许在表的前端(front)进行删除操作,而在表的后端(rear)进行插入操作.进行插入操作的端称为队尾,进行删除操作的端称为队头.队列中没有元素时,称为空队列. 在队列这 ...
- HDU4939Stupid Tower Defense (有思想的dp)
Stupid Tower Defense Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Oth ...
- qt槽函数中,窗口镶嵌窗口的问题,求解
my_label=newQLabel(ui->widget); my_Label->setText("yvhvv"); 我把这插入到构造函数中,正确显示. 我把这插入到 ...
- javascript (八) 语法格式
JavaScript 对大小写敏感. JavaScript 对大小写是敏感的. 当编写 JavaScript 语句时,请留意是否关闭大小写切换键. 函数 getElementById 与 getEle ...
- 枚举算法总结 coming~^.*
感谢CJ同学监督╭(╯^╰)╮.从放假到现在都木有更新博客了~噶呜~小娘谨记教诲,每天会更新博客==!! 看了一下POJ训练计划,虽然已经零零散散做了40多道题了,还是从头开始整理一下漏掉的知识点.T ...
- Swift - 将表格UITableView滚动条移动到底部
有时我们需要通过代码自动将表格UITableView滚动条移动到尾部,只需要使用scrollToRowAtIndexPath方法即可,代码如下: 1 2 3 4 5 var secon = 1 //最 ...
- WKE——Webkit精简的纯C接口的浏览器
以前不知道有这个东西 https://github.com/cexer/wke http://blog.csdn.net/weolar/article/details/50383491 http:// ...