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
随机推荐
- sql为数字添加千分位(也就是钱的格式)
感觉这个东西在项目中用得挺多的,之前在前台页面是用正则来处理,现在由于是数据查询,所以直接在查出数据的时候将其转为指定的千分位格式,省的前台再处理,不讲原理,因为我也看不懂,不过会用就行了,在网上找了 ...
- CF437D(The Child and Zoo)最小生成树
题目: D. The Child and Zoo time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- eclipse3.2 汉化 汉化包下载
1.首先去www.eclipse.org下载eclipse3.2 点击下载eclipse3.2 2.再去www.eclipse.org下载它的汉化包 请使用迅雷等下载工具下载汉化包 注意不同版 ...
- Opencv笔记(1) 命名规则数据结构(CvMat,...)
网上搜索了很多,检查中发现的信息劣势,检查源代码 同Cv为类的开始.包含详细的数据不(仅存储指针) CvMat typedef struct CvMat { int type; int step; / ...
- Windows消息队列
一 Windows中有一个系统消息队列,对于每一个正在执行的Windows应用程序,系统为其建立一个“消息队列”,即应用程序队列,用来存放该程序可能 创建的各种窗口的消息.应用程序中含有一段称作“消息 ...
- 【ASP.NET Web API教程】3.3 通过WPF应用程序调用Web API(C#)
原文:[ASP.NET Web API教程]3.3 通过WPF应用程序调用Web API(C#) 注:本文是[ASP.NET Web API系列教程]的一部分,如果您是第一次看本博客文章,请先看前面的 ...
- 使用CUNIT测试
使用CUNIT测试 一:概述 CUnit是一个c语言的单元测试框架,它是以静态链接库的形式,连接到用户代码中的,主要的功能就是提供了语义丰富的断言和多种测试结果输出接口,可以方便地生成测试报告. 但是 ...
- svn跨机备份
#!/bin/sh svn_bak_dir='/svndata/cloudil' svn_server='svn://172.16.40.200:9999' user=adminread pass=a ...
- MySQL 关闭FOREIGN_KEY_CHECKS检查
SET FOREIGN_KEY_CHECKS=0; truncate table QRTZ_BLOB_TRIGGERS; truncate table QRTZ_CALENDARS; truncate ...
- Nginx之http_image_filter_module模块使用
一.安装 #yum install gd-devel # #./configure --prefix=/usr/local/nginx \ # --with-debug \ # --with-http ...