题目链接: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)的更多相关文章

  1. Light OJ 1004 - Monkey Banana Problem(DP)

    题目大意: 给你一菱形的数字阵,问从最上面走到最下面所能获得的最大值是多少? #include<cstdio> #include<cstring> #include<io ...

  2. (LightOJ 1004) Monkey Banana Problem 简单dp

    You are in the world of mathematics to solve the great "Monkey Banana Problem". It states ...

  3. CF1096D Easy Problem(DP)

    貌似最近刷了好多的CF题…… 题目链接:CF原网 洛谷 题目大意:有一个长度为 $n$ 的字符串 $s$,删除第 $i$ 个字符需要代价 $a_i$.问使得 $s$ 不含有子序列(不是子串)" ...

  4. Codeforces Round #367 (Div. 2) C. Hard problem(DP)

    Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...

  5. 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个数 -> ...

  6. Monkey and Banana---hdu1069(dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 题意就是给你n种长方体每种类型不限制个数,然后我们把它们一个个堆起来,并且要满足下面的要比上面的 ...

  7. LightOJ 1033 Generating Palindromes(dp)

    LightOJ 1033  Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...

  8. lightOJ 1047 Neighbor House (DP)

    lightOJ 1047   Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730# ...

  9. UVA11125 - Arrange Some Marbles(dp)

    UVA11125 - Arrange Some Marbles(dp) option=com_onlinejudge&Itemid=8&category=24&page=sho ...

随机推荐

  1. 【CTSC 2015】&【APIO 2015】酱油记

    蒟蒻有幸参加了神犇云集的CTSC & APIO 2015,感觉真是被虐成傻逼了……这几天一直没更新博客,今天就来补一下吧~~(不过不是题解……) Day 0 从太原到北京现在坐高铁只需3小时= ...

  2. Leetcode#127 Word Ladder

    原题地址 BFS Word Ladder II的简化版(参见这篇文章) 由于只需要计算步数,所以简单许多. 代码: int ladderLength(string start, string end, ...

  3. Spring Mvc 返回机制

    转自:http://jianzh5.iteye.com/blog/1909234 Spring Mvc 有如下的几种返回方式: ModelAndView, Model, ModelMap, Map, ...

  4. [百度空间] [原]android下的各种坑

    一堆so文件安装不正确: apk里面都是全的, 但是安装完后/data/data/$pkg/lib下面就没有 google了好长时间没有结果.最后发现是因为没库有加lib前缀(当时想了一下觉得不加更好 ...

  5. oracle Array类型作为参数传入函数(存储过程) 大字符串参数解决方案

    1. 创建自定义的类型.由于Oracle没有提供现成的array类型,这里用table类型来模拟. CREATE OR REPLACE TYPE varchar_array is Table OF v ...

  6. SQL注入测试用例

    //看看是什么权限的and 1=(Select IS_MEMBER('db_owner'))And char(124)%2BCast(IS_MEMBER('db_owner') as varchar( ...

  7. oom日志查看

    这通常会触发 Linux 内核里的 Out of Memory (OOM) killer,OOM killer 会杀掉某个进程以腾出内存留给系统用,不致于让系统立刻崩溃.如果检查相关的日志文件(/va ...

  8. POJ 1607

    #include<iostream> #include<iomanip> using namespace std; int main() { //freopen("a ...

  9. CS001: 清理浮动的几种方法以及对应规范说明

    以下内容转自 http://www.w3help.org/zh-cn/casestudies/001 <!==================> 前言 浮动 Floats 是 CSS 中的 ...

  10. 跨平台的加密算法XXTEA 的封装

    跨平台的加密算法XXTEA 的封装 XXTEA算法的结构非常简单,只需要执行加法.异或和寄存的硬件即可,且软件实现的代码非常短小,具有可移植性. 维基百科地址:http://en.wikipedia. ...