POJ3176--Cow Bowling(动态规划)
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
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
int data[][];
int dp[];
int main(){
int n;
cin>>n;
for(int i=;i<=n;i++)
for(int j=;j<=i;j++)
cin>>data[i][j];
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++){
for(int j=i;j>=;j--){//这里为何j要逆序开始算呢?等号右边的dp数组是对应的i-1,如果升学计算的话,等号左边被赋值之后,也就意味着i-1数组被修改了,而下次计算正好需要这次修改的原来的数组的值
dp[j]=max(dp[j-],dp[j])+data[i][j];
}
}
int m=dp[];
for(int i=;i<=n;i++){
if(dp[i]>m)
m=dp[i];
}
cout<<m;
return ;
}
#include<iostream>
#include<string.h>
using namespace std;
int way[MAXN],dp[MAXN];
int N;
void Input()
{
cin>>N;
memset(dp,,sizeof(dp));
for (int i=; i<=N; i++)
{
for (int j=; j<=i; j++)
scanf("%d",&way[j]);
for (int j=i; j>=; j--)
dp[j]=max(dp[j],dp[j-])+way[j];
}
}
void Output()
{
int ret=dp[];
for (int i=; i<=N; i++)
if (ret<dp[i]) ret=dp[i];
cout<<ret<<endl;
}
int main()
{
Input();
Output();
return ;
}
POJ3176--Cow Bowling(动态规划)的更多相关文章
- POJ3176——Cow Bowling(动态规划)
Cow Bowling DescriptionThe cows don't use actual bowling balls when they go bowling. They each take ...
- 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 ...
- POJ - 3176 Cow Bowling 动态规划
动态规划:多阶段决策问题,每步求解的问题是后面阶段问题求解的子问题,每步决策将依赖于以前步骤的决策结果.(可以用于组合优化问题) 优化原则:一个最优决策序列的任何子序列本身一定是相当于子序列初始和结束 ...
- 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(数字三角形问题)
地址:http://poj.org/problem?id=3176 题目解析:没什么好说的,之前上课时老师讲过.从下往上找,每一个三角形的顶点可由两个角加上顶点的值 两种方式得到 ,用dp数组保存下最 ...
- POJ 3176 Cow Bowling(dp)
POJ 3176 Cow Bowling 题目简化即为从一个三角形数列的顶端沿对角线走到底端,所取得的和最大值 7 * 3 8 * 8 1 0 * 2 7 4 4 * 4 5 2 6 5 该走法即为最 ...
- POJ 3176 Cow Bowling
Cow Bowling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13016 Accepted: 8598 Desc ...
- Cow Bowling
Cow Bowling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15585 Accepted: 10363 Descrip ...
- POJ 3176:Cow Bowling
Cow Bowling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13464 Accepted: 8897 Desc ...
随机推荐
- [转]C#中HttpClient使用注意:预热与长连接
最近在测试一个第三方API,准备集成在我们的网站应用中.API的调用使用的是.NET中的HttpClient,由于这个API会在关键业务中用到,对调用API的整体响应速度有严格要求,所以对HttpCl ...
- Bonding
一.简介 双网卡配置设置虚拟为一个网卡实现网卡的冗余,其中一个网卡坏掉后网络通信仍可正常使用,实现网卡层面的负载均衡和高可用性 二.原理 网卡工作在混杂(promisc)模式,接收到达网卡的所有数 ...
- C# Contains 包含空字符串的问题
一个基本的条件判断,之前没有遇到,这次遇到后,感觉真是这些年白写程序了. if(("1,2,3").Contains("")) { MessageBox.Sho ...
- stl中顺序性容器,关联容器两者粗略解释
什么是容器 首先,我们必须理解一下什么是容器,在C++ 中容器被定义为:在数据存储上,有一种对象类型,它可以持有其它对象或指向其它对像的指针,这种对象类型就叫做容器.很简单,容器就是保存其它对象的对象 ...
- MacDev.GarbageCollectionIsDeprecated-WhenXcodeCompileMacAppProject
Garbage Collection is not supported 当Xcode编译Mac OSX App时报错:"Garbage Collection is not supported ...
- TP 真阳性 TN FP FN
TP.True Positive 真阳性:预测为正,实际也为正 FP.False Positive 假阳性:预测为正,实际为负 FN.False Negative 假阴性:预测与负.实际为正 T ...
- Java的OOP三大特征之一——封装
面向对象三大特征之一 封装 继承 多态 封装性就是把类(对象)的属性和行为结合成一个独立的相同单位,并尽可能隐蔽类(对象)的内部细节,对外形成一个边界,只保留有限的对外接口使之与外部发生联系. ...
- if __name__ == '__main__的理解
模块之间引用不能循环成环,圆圈 模块的收搜 !!!把模块当作脚本执行 什么叫模块:py文件,如果一个py文件被导入了,他就是一个模块, 模块没有具体的调用过程 但是能对外提供功能 什么叫脚 ...
- Luogu 3421 [POI2005]SKO-Knights - Exgcd
Description 给出一个骑士的 $N$种 中行走的方式 $(a_i, b_i)$, 可以使骑士的坐标$(-a,-b)$或$(+a,+b)$. 我们需要找出 第二个骑士的 两种行走方式 $(c_ ...
- vs2010打开qt的.pro文件时错误解决办法
注意:qt creator工程中一般都已经存在*.pro文件,里面存放着一些自己配置的包含头文件和lib库文的信息,最好不要再重新使用qmake -project生成,若重新生成,则可能要重新增加配置 ...