POJ-3176-Cow Bowling
2016-07-26 22:04
260 查看
Cow Bowling
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:
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
Sample Output
Hint
Explanation of the sample:
The highest score is achievable by traversing the cows as shown above.
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<queue>
#include<algorithm>
using namespace std;
int main()
{
int n;
scanf("%d", &n);
int a[400][400];
memset(a, 0, sizeof(a));
for(int i = 1; i<=n; ++i)
{
for(int j = 1; j<=i;++j)
scanf("%d",&a[i][j]);
}
for(int i = n; i>1;--i)
{
for(int j = 1; j<i;++j)
{
a[i-1][j]+=max(a[i][j], a[i][j+1]);
}
}
printf("%d\n",a[1][1]);
return 0;
}
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 17178 | Accepted: 11462 |
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
5 7 3 8 8 1 0 2 7 4 4 4 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<stdio.h>
#include<string.h>
#include<math.h>
#include<queue>
#include<algorithm>
using namespace std;
int main()
{
int n;
scanf("%d", &n);
int a[400][400];
memset(a, 0, sizeof(a));
for(int i = 1; i<=n; ++i)
{
for(int j = 1; j<=i;++j)
scanf("%d",&a[i][j]);
}
for(int i = n; i>1;--i)
{
for(int j = 1; j<i;++j)
{
a[i-1][j]+=max(a[i][j], a[i][j+1]);
}
}
printf("%d\n",a[1][1]);
return 0;
}
相关文章推荐
- android开发性能优化经验总结二
- 常见的架构模式
- 字符串-10115 Automatic Editing
- FTP主动与被动传输引发的协议那些事
- 第20条:类层次优先于标签类
- 深度学习斯坦福cs231n 课程笔记
- Java的基础知识4——容器
- UE4 启动器一系列问题处理链接
- ID卡的原理和ID卡复制器
- 顺序表应用5:有序顺序表归并
- 0726linux基础内容小记
- 企业信息化快速开发平台 JeeSite
- MySQL学习系列一---命令行连接mysql和执行sql文件
- C#使用Process类杀死进程,执行命令等
- redis学习笔记之list类型
- 使用Spring4+Maven构建webapp项目
- 哈希函数相关
- 签到
- MongoDB 删除集合
- MongoDB 删除集合