POJ 3176:Cow Bowling
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 13464 | Accepted: 8897 |
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
The highest score is achievable by traversing the cows as shown above.
简单的数塔DP问题。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream> using namespace std; const int M = 350 +5;
int Cow[M][M]; int main()
{
int n;
while(scanf("%d", &n)!=EOF)
{
memset(Cow, 0, sizeof(Cow));
for(int i=1; i<=n; i++)
for(int j=1; j<=i; j++)
{
scanf("%d", &Cow[i][j]);
}
for(int i=n-1; i>=1; i--)
for(int j=1; j<=i; j++)
Cow[i][j]+=max(Cow[i+1][j], Cow[i+1][j+1]);
cout<<Cow[1][1]<<endl;
} return 0;
}
POJ 3176:Cow Bowling的更多相关文章
- 【POJ 3176】Cow Bowling
题 Description The cows don't use actual bowling balls when they go bowling. They each take a number ...
- 【POJ 3176】Cow Bowling(DP)
题 Description The cows don't use actual bowling balls when they go bowling. They each take a number ...
- POJ 3673:Cow Multiplication
Cow Multiplication Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12210 Accepted: 85 ...
- POJ 2184:Cow Exhibition(01背包变形)
题意:有n个奶牛,每个奶牛有一个smart值和一个fun值,可能为正也可能为负,要求选出n只奶牛使他们smart值的和s与fun值得和f都非负,且s+f值要求最大. 分析: 一道很好的背包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 1163 The Triangle &poj 3176 Cow Bowling (dp)
id=1163">链接:poj 1163 题意:输入一个n层的三角形.第i层有i个数,求从第1层到第n层的全部路线中.权值之和最大的路线. 规定:第i层的某个数仅仅能连线走到第i+1层 ...
- POJ 3176 Cow Bowling
Cow Bowling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13016 Accepted: 8598 Desc ...
- POJ 3176 简单DP
Cow Bowling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16448 Accepted: 10957 Descrip ...
- POJ 3617 Best Cow Line(最佳奶牛队伍)
POJ 3617 Best Cow Line Time Limit: 1000MS Memory Limit: 65536K [Description] [题目描述] FJ is about to t ...
随机推荐
- U盘安装centos 7 提示 “Warning: /dev/root does not exist, could not boot” 解决办法
1.查询磁盘 cd /dev ls 2.查询结果 sda 是我的硬盘对应的文件名(我机子只有一块硬盘),所以sda4就是U盘对应的文件名了,可以看到是sda4.至此我们重启一下,回到第一个图片所示的界 ...
- spring利用扫描方式对bean的处理(对任何版本如何获取xml配置信息的处理)
利用扫描的方式将组件注入容器,就也可以不用操作bean来实例化对象了. 下面我做一个例子 我用的spring3.2.2版本的 首先写一个spring.xml. <?xml version=&qu ...
- Linux/Kubuntu/Ubuntu下安装字体
1>获得字体文件*.ttf,免费下载地址:http://www.font5.com.cn/ simfang.ttf 仿宋体 simhei.ttf 黑体 simkai.ttf 楷体 simsun. ...
- IE 下使用firebug
javascript :var firebug=document.createElement('script');firebug.setAttribute('src','http://getfireb ...
- hdu4708 Rotation Lock Puzzle
Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- 杭电ACM1408——盐水的故事
简单的题目,RT,就能够写出代码.须要注意的是类型的应用,应该用浮点型. 以下的是AC的代码: #include <iostream> using namespace std; int m ...
- Extjs实现树形结构三连选
当项目中需要一个部门人员选择或者省市县地域连选时,就需要树形结构的连选. 再此,写了一个简单的树形结构三连选功能,模拟从后台读取数据和处理数据(欢迎大家交流指正). 代码如下: 循环创建三棵树,其中只 ...
- Let’s do this!新手程序员的入门指南(转)
计算机科学(Computer Science)无疑是现在最热门的学科之一,这领域的工作薪水高.工作时间弹性,而且科技业对工程师.开发者的需求至今有增无减,科技龙头们随时虎视眈眈着出色的程式开发者.创意 ...
- js 动态切换视频
如图所示,想要一个这样的效果,就是点击下面视频标题时,上面的视频跟着切换,但是要求页面不重新加载. 参考文章在这里 这里贴上部分代码供大家参考. <li id="about_li6&q ...
- 基于visual Studio2013解决面试题之0807strstr函数
题目