[LightOJ1004]Monkey Banana Problem(dp)
题目链接:http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1004
题意:数塔的变形,上面一个下面一个,看清楚了直接做就行了。
上半部分转移方程dp(i,j)=max(dp(i-1,j),dp(i-1,j+1))+G(i,j)
下半部分转移方程dp(i,j)=max(dp(i-1,j-1),dp(i-1,j))+G(i,j)
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath> using namespace std; const int maxn = ;
int n, m;
int dp[maxn][maxn];
int G[maxn][maxn]; int main() {
// freopen("in", "r", stdin);
int T;
scanf("%d", &T);
for(int _ = ; _ <= T; _++) {
scanf("%d", &n);
int cnt = ;
bool flag = ;
for(int i = ; i <= * n - ; i++) {
if(!flag) cnt++;
for(int j = ; j <= cnt; j++) {
scanf("%d", &G[i][j]);
}
if(cnt > n - ) flag = ;
if(flag) cnt--;
}
cnt = ;
flag = ;
memset(dp, , sizeof(dp));
for(int i = ; i <= * n - ; i++) {
if(!flag) cnt++;
for(int j = ; j <= cnt; j++) {
if(i == && j == ) {
dp[][] = G[][];
continue;
}
if(!flag) dp[i][j] = G[i][j] + max(dp[i-][j-], dp[i-][j]);
else dp[i][j] = G[i][j] + max(dp[i-][j+], dp[i-][j]);
}
if(cnt > n - ) flag = ;
if(flag) cnt--;
}
printf("Case %d: %d\n", _, dp[*n-][]);
}
return ;
}
[LightOJ1004]Monkey Banana Problem(dp)的更多相关文章
- Light OJ 1004 - Monkey Banana Problem(DP)
题目大意: 给你一菱形的数字阵,问从最上面走到最下面所能获得的最大值是多少? #include<cstdio> #include<cstring> #include<io ...
- (LightOJ 1004) Monkey Banana Problem 简单dp
You are in the world of mathematics to solve the great "Monkey Banana Problem". It states ...
- CF1096D Easy Problem(DP)
貌似最近刷了好多的CF题…… 题目链接:CF原网 洛谷 题目大意:有一个长度为 $n$ 的字符串 $s$,删除第 $i$ 个字符需要代价 $a_i$.问使得 $s$ 不含有子序列(不是子串)" ...
- Codeforces Round #367 (Div. 2) C. Hard problem(DP)
Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...
- HDU 5464 ( Clarke and problem ) (dp)
dp[i][j] := 前i个数和为j的情况(mod p) dp[i][j] 分两种情况 1.不选取第i个数 -> dp[i][j] = dp[i-1][j] 2. 选取第i个数 -> ...
- Monkey and Banana---hdu1069(dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 题意就是给你n种长方体每种类型不限制个数,然后我们把它们一个个堆起来,并且要满足下面的要比上面的 ...
- LightOJ 1033 Generating Palindromes(dp)
LightOJ 1033 Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...
- lightOJ 1047 Neighbor House (DP)
lightOJ 1047 Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730# ...
- UVA11125 - Arrange Some Marbles(dp)
UVA11125 - Arrange Some Marbles(dp) option=com_onlinejudge&Itemid=8&category=24&page=sho ...
随机推荐
- O(V*n)的多重背包问题
多重背包问题: 有n件物品,第i件价值为wi,质量为vi,有c1件,问,给定容量V,求获得的最大价值. 朴素做法: 视为0,1,2,...,k种物品的分组背包 [每组只能选一个] f[i][j]=Ma ...
- BZOJ3170: [Tjoi 2013]松鼠聚会
3170: [Tjoi 2013]松鼠聚会 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 531 Solved: 249[Submit][Statu ...
- 我的这10年——从机械绘图 到 炼油 到 微软MVP 的华丽转身
年底了,各种总结计划满天飞,有空的时候我也一直在思考这么多年,是怎么过来的.也曾经很迷茫,希望经验和经历能给大家一点带来一点正能量的东西.10年很长,10年前说实话我没有思考过现在的样子,但10年前的 ...
- [工作积累] Android system dialog with native callback
JNI: invoke java dialog with native callback: store native function address in java, and invoke nati ...
- ASP.NET中的事件处理
一.ASP.NET中的事件主要支持3个主要的事件组:1.包含在asp.net生成页面时自动生成,我们使用这些事件建立页面(如page_load等)2.包含了用户与页面交互时发生的所有事件(这种最强大) ...
- c#比较器 排序
原地址:http://blog.csdn.net/xutao_ustc/article/details/6314057 class Program { static void Main(string[ ...
- (转)Eclipse平台技术概述
转载:周金根 http://zhoujg.blog.51cto.com/1281471/516833 Eclipse:Eclipse平台技术概述 2010-10-19 13:35:00 标签:E ...
- iOS视频录制裁剪合成
网址链接: 视频裁剪合并:http://blog.sina.com.cn/s/blog_64ea868501018jx3.html 视频之定义裁剪高宽度:http://www.cocoachina.c ...
- POJ 3034 Whac-a-Mole(DP)
题目链接 题意 : 在一个二维直角坐标系中,有n×n个洞,每个洞的坐标为(x,y), 0 ≤ x, y < n,给你一把锤子可以打到地鼠,最开始的时候,你可以把锤子放在任何地方,如果你上一秒在( ...
- BZOJ 1015: [JSOI2008]星球大战starwar 并查集
1015: [JSOI2008]星球大战starwar Description 很久以前,在一个遥远的星系,一个黑暗的帝国靠着它的超级武器统治者整个星系.某一天,凭着一个偶然的机遇,一支反抗军摧毁了帝 ...