POJ-3176 Cow Bowling【基础DP】
来源:互联网 发布:对网络直播的看法作文 编辑:程序博客网 时间:2024/06/05 08:20
Cow Bowling
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 17284 Accepted: 11538
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;int map[400][400];int wcn[400][400];int main(){int n;while(scanf("%d",&n)!=EOF){int wc=1;for(int i=1;i<=n;i++){for(int j=1;j<=wc;j++){int nn;scanf("%d",&nn);map[i][j]=wcn[i][j]=nn;}wc++;}wc=1;for(int i=1;i<n;i++){for(int j=1;j<=wc;j++){if(j==1){map[i+1][j]+=map[i][j];map[i+1][j+1]+=map[i][j];}else if(j==wc&&wc!=1){map[i+1][j+1]+=map[i][j];if((wcn[i+1][j]+map[i][j])>map[i+1][j]){map[i+1][j]=wcn[i+1][j]+map[i][j];}}else{if((wcn[i+1][j]+map[i][j])>map[i+1][j]){map[i+1][j]=wcn[i+1][j]+map[i][j];}if((wcn[i+1][j+1]+map[i][j])>map[i+1][j+1]){map[i+1][j+1]=wcn[i+1][j+1]+map[i][j];}}}wc++;}int ans=0;for(int i=1;i<=n;i++){if(map[n][i]>ans){ans=map[n][i];}}printf("%d\n",ans);}return 0;}
0 0
- POJ 3176 Cow Bowling(基础DP)
- POJ-3176 Cow Bowling【基础DP】
- Cow Bowling(POJ, 3176, 基础dp)
- POJ 3176 Cow Bowling DP
- poj-3176-Cow Bowling-dp
- poj 3176 Cow Bowling (DP)
- poj 3176 Cow Bowling dp
- POJ 3176 Cow Bowling DP
- poj 3176Cow Bowling DP
- Poj 3176 Cow Bowling【dp】
- POJ 3176 Cow Bowling (dp)
- poj 3176 -- Cow Bowling (dp)
- POJ 3176 Cow Bowling (简单DP)
- POJ 3176 Cow Bowling (简单DP)
- poj 3176 Cow Bowling 数塔dp
- POJ 3176-Cow Bowling (简单DP)
- POJ 3176 Cow Bowling (简单DP)
- POJ 3176 Cow Bowling (dp)
- Android初学之Runnable和Thread
- 单点登录的实现原理
- Unity单例模式
- 九度OJ 1069 查找学生信息
- 行为识别
- POJ-3176 Cow Bowling【基础DP】
- RxJava(三)简单常用操作符
- pdf格式转换之pdf转换成word文档的方法
- nyoj325 zb的生日 (深度搜索)(动态规划)
- Linux gdb用法
- JSP实现验证码
- RTSP - RTP over TCP
- Line Reflection
- bzoj 2733 永无乡 Treap+并查集