ligh oj 1004 - Monkey Banana Problem
来源:互联网 发布:java培训骗局 编辑:程序博客网 时间:2024/03/28 18:56
You are in the world of mathematics to solve the great "Monkey Banana Problem". It states that, a monkey enters into a diamond shaped two dimensional array and can jump in any of the adjacent cells down from its current position (see figure). While moving from one cell to another, the monkey eats all the bananas kept in that cell. The monkey enters into the array from the upper part and goes out through the lower part. Find the maximum number of bananas the monkey can eat.
Input
Input starts with an integer T (≤ 50), denoting the number of test cases.
Every case starts with an integer N (1 ≤ N ≤ 100). It denotes that, there will be 2*N - 1 rows. The ith (1 ≤ i ≤ N) line of next N lines contains exactly i numbers. Then there will be N - 1lines. The jth (1 ≤ j < N) line contains N - j integers. Each number is greater than zero and less than 215.
Output
For each case, print the case number and maximum number of bananas eaten by the monkey.
Sample Input
Output for Sample Input
2
4
7
6 4
2 5 10
9 8 12 2
2 12 7
8 2
10
2
1
2 3
1
Case 1: 63
Case 2: 5
Note
Dataset is huge, use faster I/O methods.
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int a[200][200],dp[200][200];int main(){ int n,r,ca=1;scanf("%d",&r) ;while(r--){scanf("%d",&n);for(int i=1;i<=n;i++)for(int j=1;j<=i;j++){scanf("%d",&a[i][j]);dp[i][j]=0;} for(int i=n+1;i<=2*n-1;i++) for(int j=1;j<=2*n-i;j++) {scanf("%d",&a[i][j]);dp[i][j]=0; } dp[1][1]=a[1][1]; for(int i=1;i<n;i++) for(int j=1;j<=i;j++) { dp[i+1][j]=max(dp[i+1][j],a[i+1][j]+dp[i][j]); dp[i+1][j+1]=max(dp[i+1][j+1],a[i+1][j+1]+dp[i][j]); } for(int i=n+1;i<=2*n-1;i++) for(int j=1;j<=2*n-i;j++) dp[i][j]=max(dp[i-1][j],dp[i-1][j+1])+a[i][j]; printf("Case %d: %d\n",ca++,dp[2*n-1][1]); } }
- ligh oj 1004 - Monkey Banana Problem
- 【DP】 Light OJ 1004 Monkey Banana Problem
- light oj 1004 - Monkey Banana Problem
- Light oj 1004 - Monkey Banana Problem(DP)
- Light OJ 1004 - Monkey Banana Problem dp题解
- LightOJ 1004 - Monkey Banana Problem
- lightoj 1004 - Monkey Banana Problem
- LightOJ 1004 Monkey Banana Problem
- LightOJ 1004 - Monkey Banana Problem
- lightOJ 1004 - Monkey Banana Problem
- 1004 - Monkey Banana Problem (dp)
- lightoj 1004 - Monkey Banana Problem
- LightOJ 1004 Monkey Banana Problem
- Light oj-1004 - Monkey Banana Problem,数字三角形的变形版~
- LightOJ 1004 - Monkey Banana Problem 【DP】
- LightOJ 1004 - Monkey Banana Problem (dp)
- LightOJ - 1004 Monkey Banana Problem(DP)
- LightOJ 1004 - Monkey Banana Problem(dp)
- Linux2.6PCI驱动加载原理
- Java应用程序
- 概率算法求解圆周率π
- 几何方法---测试盒子 二
- TreeView
- ligh oj 1004 - Monkey Banana Problem
- hdu 2254 奥运
- C++模板类的继承1 :模板类继承模板类
- API相关工作的个人总结_Sandcastle简要使用介绍
- Android学习系列-把文件保存到SD卡上面(6)
- HDU4514(非连通图的环判断与图中最长链)
- one of the key features of distributed application-managemeability
- opencv之绘图
- [IOS]包含增删改查移动的tableView展示+plist文件保存+程序意外退出保存Demo