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
随机推荐
- Beauty of Array
Description Edward has an array A with N integers. He defines the beauty of an array as the summatio ...
- wiki 3143 二叉树的前序、中序及后序遍历
先序遍历:訪问根.遍历左子树.遍历右子树,简称:DLR. 中序遍历:遍历左子树,訪问根,遍历右子树,简称:LDR. 后序遍历:遍历左子树,遍历右子树.訪问根.简称:LRD. 数组搞的: #pragma ...
- 在VC++中启用内存泄露检测
检测内存泄漏的主要工具是调试器和 CRT 调试堆函数.若要启用调试堆函数,请在程序中包括以下语句: #define CRTDBG_MAP_ALLOC#include <stdlib.h># ...
- ajax+jsp实现三级联动下拉框
js文件sjld.js : $(document).ready( function(){ $.ajax({ url:"bindZ", type:"get", ...
- Linux 双网卡绑定技术
bond技术是在linux2.4以后加入内核. 一般步骤是1.把bonding模块加入内核, 2 编辑要绑定的网卡设置,去除地址设定 3 添加bond设备,设置地址等配置 4 重启网络 5 在交换机 ...
- PAIP: Paradigms of Artificial Intelligence Programming
PAIP: Paradigms of Artificial Intelligence Programming PAIP: Paradigms of Artificial Intelligence Pr ...
- QUIC简单介绍
QUIC,即Quick UDP Internet Connection,类似于SPDY,相同也是由Google公司在现有已存协议之上进行了扩展设计,而旨在降低网络延迟.之前我曾介绍过SPDY的相关信息 ...
- django中mysql数据库设置错误解决方法
刚在django中settings.py进行设置mysql数据库. 当进行执行python manage.py shell命令时会报以下错误: 只需要在settings.py中 DATABASES = ...
- Delphi中类的运行期TypeInfo信息结构说明
Delphi中类的运行期TypeInfo信息结构说明 CnPack 开源软件项目 2007-09-19 21:55:58 Delphi中类的运行期TypeInfo信息结构说明作者:刘啸CnPack开发 ...
- [Android学习笔记]some tips
集合合并去重: listA.removeAll(listB); listA.addAll(listB); android:singleLine="true"//单行显示 andro ...