poj3176(DP)
来源:互联网 发布:深圳软件外包公司排名 编辑:程序博客网 时间:2024/05/18 23:26
Cow Bowling
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 14752 Accepted: 9808
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:
Given a triangle with N (1 <= N <= 350) rows, determine the highest possible sum achievable.
7 3 8 8 1 0 2 7 4 4 4 5 2 6 5Then 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.
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<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define maxn 351int dp[maxn][maxn];int a[maxn][maxn];int n;void solve(){ for(int i=n-1;i>=0;i--) { for(int j=0;j<=i;j++) { dp[i][j]=max(dp[i+1][j],dp[i+1][j+1])+a[i][j]; } } printf("%d\n",dp[0][0]);}int main(){ while(scanf("%d",&n)!=EOF) { for(int i=0;i<n;i++) { for(int j=0;j<=i;j++) { scanf("%d",&a[i][j]); } } memset(dp,0,sizeof(dp)); solve(); } return 0;}
0 0
- poj3176 dp
- poj3176(DP)
- POJ3176(DP)
- poj3176 简单dp
- poj3176 Cow Bowling DP
- POJ3176 DP 数塔
- [dp]poj3176 Cow Bowling
- poj3176 dp 数字三角形
- POJ3176 简单DP....
- POJ3176 DP水题
- poj3176【简单DP】
- [DP]poj3176 Cow Bowling
- POJ3176-Cow Bowling(dp)
- POJ3176-Cow Bowling-简单dp
- poj3176
- poj3176
- poj3176
- poj3176
- 2015腾讯实习生笔试小结
- 【Android】ViewPager实现图片左右滑动播放及添加点击事件
- Jquery.validation.js学习
- spring中使用@RequestBody,对应的bean中属性名大写注入为空的解决方法
- 数据库第二章作业
- poj3176(DP)
- Android入门:通过AIDL进行进程间通信
- eventfd以及epoll原理分析
- spring redis入门
- Android入门:绑定本地服务
- Android开发_DrawerLayout实现抽屉布局
- 虚拟机VmWare 无法连接网络
- (六)K-means Clustering and Principal Component Analysis[K-means聚类&主元分析]
- ifarme使用jquery