博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ-3176 Cow Bowling
阅读量:4962 次
发布时间:2019-06-12

本文共 1774 字,大约阅读时间需要 5 分钟。

Language:Default
Cow Bowling
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 22568   Accepted: 14886

Description

The cows don't use actual bowling balls when they go bowling. They each take a number (in the range 0..99), though, and line up in a standard bowling-pin-like triangle like this: 
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

Line 1: A single integer, N 
Lines 2..N+1: Line i+1 contains i space-separated integers that represent row i of the triangle.

Output

Line 1: The largest sum achievable using the traversal rules

Sample Input

573 88 1 02 7 4 44 5 2 6 5

Sample Output

30

Hint

Explanation of the sample: 
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.
 
//递推一下就好了,想一下这一步是怎么来的就出来递推式了 #include
#include
#include
using namespace std;int n,map[1000][1000],dp[1000][1000];int ans=0;int main(){ cin>>n; for(int i=1;i<=n;i++) { for(int j=1;j<=i;j++) { cin>>map[i][j]; } } int i,j; for(i=1;i<=n;i++) { for(j=1;j<=i;j++) { dp[i][j]=max(dp[i-1][j],dp[i-1][j-1])+map[i][j]; ans=max(ans,dp[i][j]); } } cout<

 

转载于:https://www.cnblogs.com/wpbing/p/9507836.html

你可能感兴趣的文章
求输入成绩的平均分
查看>>
php PDO (转载)
查看>>
wordpress自动截取文章摘要代码
查看>>
[置顶] 一名优秀的程序设计师是如何管理知识的?
查看>>
scanf和gets
查看>>
highcharts 图表实例
查看>>
ubuntu下如何查看用户登录及系统授权相关信息
查看>>
秋季学期学习总结
查看>>
SpringBoot 优化内嵌的Tomcat
查看>>
【LaTeX】E喵的LaTeX新手入门教程(1)准备篇
查看>>
highcharts曲线图
查看>>
extjs动态改变样式
查看>>
PL/SQL Developer 查询的数据有乱码或者where 字段名=字段值 查不出来数据
查看>>
宏定义
查看>>
ubuntu12.04 串口登录系统配置
查看>>
poj3061
查看>>
linux--多进程进行文件拷贝
查看>>
笔记:git基本操作
查看>>
Gold Smith第一章
查看>>
生成php所需要的APNS Service pem证书的步骤
查看>>