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
随机推荐
- CEdit 样式与消息 解析
编辑框(Edit)控件实际上是一个简易的文本编辑器,用户可以在编辑框中输入可添加或插入文本.还有复制.粘贴.剪切.删除等编辑功能. 应用程序用CreateWindowEx创建编辑框控件时,可根据控件的 ...
- jsp:setProperty
类声明: package test; public class Student { private int age; public int getAge() { return ...
- Hibernate核心接口
1.Configuration接口 Configuration负责管理Hibernate的配置信息. 2,SessionFactory接口 SessionFactory负责创建Session实例,能够 ...
- J2EE开发框架搭建(1) - maven搭建多项目
怎样使用maven搭建多个项目 1. 创建一个maven project 2. 在frame-parent项目上面点击右键,新建Maven Module 3. 完毕之后再建立一个web项目 4. 依照 ...
- 提升Delphi编程效率必须使用的快捷键(Delphi2007版本)
1. [CTRL+空格] [CTRL+SHIFT+空格] 这两个快捷键都是在代码编写过程中用到的,起提示作用,使用频率最高. CTRL+空格: 在当前光标处提示有哪些变量.函数可以使用.这个功能对于无 ...
- Spring MVC+JSP实现三级联动
jsp代码 <script type="text/javascript"> $(function() { initProvinces(); }); /** * 获取省列 ...
- 百度GPSutil
================================================= package com.qcar.benz.biz.common; import com.aliba ...
- [Cocos2d-x]代码段记录
一些零碎的代码,便于以后查找 1.添加动画 //添加动画帧 CCAnimation* animation = CCAnimation::create(); ; i< ;i++) { ] = {} ...
- Scriptcase价格调整(五折销售)
芬兰诺基亚!芬兰诺基亚!最大手机公司倒闭了!王八蛋老板埃洛普,吃喝嫖赌欠下了3.5个亿,带着他的小姨子跑了!我们没有办法,拿着手机抵工资!原价都是一千多.两千多.三千多的手机,统统二百块!统统二百块! ...
- 无向图的最短路径算法JAVA实现(转)
一,问题描述 给出一个无向图,指定无向图中某个顶点作为源点.求出图中所有顶点到源点的最短路径. 无向图的最短路径其实是源点到该顶点的最少边的数目. 本文假设图的信息保存在文件中,通过读取文件来构造图. ...