[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 ...
随机推荐
- 树链剖分入门-Hdu3966 Aragorn's Story
AC通道:http://acm.hdu.edu.cn/showproblem.php?pid=3966 [题目大意] 一棵树上每个点有权值,每次支持三种操作:给[a,b]路径上的所有节点的权值加上k, ...
- C#UDP编程总结
// 如果只使用一个EndPoint,维持一个引用. private static UdpClient udpClient; static void Main(string[] args) { if ...
- Leetcode#127 Word Ladder
原题地址 BFS Word Ladder II的简化版(参见这篇文章) 由于只需要计算步数,所以简单许多. 代码: int ladderLength(string start, string end, ...
- Mybatis 自动从数据库生成entity,mapping,dao接口
1.下载需要的jar包 mybatis-generator-core-1.3.2.jar,mysql-connector-java-5.1.39.jar 2.把上面的jar包放到某个目录,并在该目录下 ...
- IIS Express 及 vs2008下使用IIS Express
介绍 IIS Express 开发 ASP.NET 的应用程序是我的主要工作.当然我会选择最适合的开发环境.客户多属于企业用户,我的开发的选择,多半是 ASP.NET Web Application ...
- CSS3实现的渐变按钮,在IE7、IE6下的滤镜使用。
.ui-button { BORDER-LEFT-WIDTH:; ; COLOR: #fff; PADDING-BOTTOM: 0px; TEXT-ALIGN: center; PADDING-T ...
- Request/Server模式
Request-------HTTP/SOAP----------Server Request模块只是Client的一小部分,Client还有HTML, Data(Text/JSON/HTML/XML ...
- WaitForTargetFPS
WaitForTargetFPS,是关于帧数限制的,你可能开了垂直同步,其实是防止撕裂.先说撕裂,在显示器的帧缓存会被不同步的显卡的帧缓存给替换掉,导致显示器显示到一半的时候,内存被换掉,你看到上频是 ...
- codeforces 439D Devu and Partitioning of the Array(有深度的模拟)
题目 //参考了网上的代码 注意答案可能超过32位 //要达成目标,就是要所有数列a的都比数列b的要小或者等于 //然后,要使最小的要和最大的一样大,就要移动(大-小)步, //要使较小的要和较大的一 ...
- POJ 1665
#include<iostream>//chengdacaizi 08.11.12 #include<iomanip> #define p 3.1415927 using na ...