题目链接: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)

  1. #include <algorithm>
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <cstring>
  5. #include <climits>
  6. #include <complex>
  7. #include <fstream>
  8. #include <cassert>
  9. #include <cstdio>
  10. #include <bitset>
  11. #include <vector>
  12. #include <deque>
  13. #include <queue>
  14. #include <stack>
  15. #include <ctime>
  16. #include <set>
  17. #include <map>
  18. #include <cmath>
  19.  
  20. using namespace std;
  21.  
  22. const int maxn = ;
  23. int n, m;
  24. int dp[maxn][maxn];
  25. int G[maxn][maxn];
  26.  
  27. int main() {
  28. // freopen("in", "r", stdin);
  29. int T;
  30. scanf("%d", &T);
  31. for(int _ = ; _ <= T; _++) {
  32. scanf("%d", &n);
  33. int cnt = ;
  34. bool flag = ;
  35. for(int i = ; i <= * n - ; i++) {
  36. if(!flag) cnt++;
  37. for(int j = ; j <= cnt; j++) {
  38. scanf("%d", &G[i][j]);
  39. }
  40. if(cnt > n - ) flag = ;
  41. if(flag) cnt--;
  42. }
  43. cnt = ;
  44. flag = ;
  45. memset(dp, , sizeof(dp));
  46. for(int i = ; i <= * n - ; i++) {
  47. if(!flag) cnt++;
  48. for(int j = ; j <= cnt; j++) {
  49. if(i == && j == ) {
  50. dp[][] = G[][];
  51. continue;
  52. }
  53. if(!flag) dp[i][j] = G[i][j] + max(dp[i-][j-], dp[i-][j]);
  54. else dp[i][j] = G[i][j] + max(dp[i-][j+], dp[i-][j]);
  55. }
  56. if(cnt > n - ) flag = ;
  57. if(flag) cnt--;
  58. }
  59. printf("Case %d: %d\n", _, dp[*n-][]);
  60. }
  61. return ;
  62. }

[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. 树链剖分入门-Hdu3966 Aragorn's Story

    AC通道:http://acm.hdu.edu.cn/showproblem.php?pid=3966 [题目大意] 一棵树上每个点有权值,每次支持三种操作:给[a,b]路径上的所有节点的权值加上k, ...

  2. C#UDP编程总结

    // 如果只使用一个EndPoint,维持一个引用. private static UdpClient udpClient; static void Main(string[] args) { if ...

  3. Leetcode#127 Word Ladder

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

  4. Mybatis 自动从数据库生成entity,mapping,dao接口

    1.下载需要的jar包 mybatis-generator-core-1.3.2.jar,mysql-connector-java-5.1.39.jar 2.把上面的jar包放到某个目录,并在该目录下 ...

  5. IIS Express 及 vs2008下使用IIS Express

    介绍 IIS Express 开发 ASP.NET 的应用程序是我的主要工作.当然我会选择最适合的开发环境.客户多属于企业用户,我的开发的选择,多半是 ASP.NET Web Application ...

  6. CSS3实现的渐变按钮,在IE7、IE6下的滤镜使用。

      .ui-button { BORDER-LEFT-WIDTH:; ; COLOR: #fff; PADDING-BOTTOM: 0px; TEXT-ALIGN: center; PADDING-T ...

  7. Request/Server模式

    Request-------HTTP/SOAP----------Server Request模块只是Client的一小部分,Client还有HTML, Data(Text/JSON/HTML/XML ...

  8. WaitForTargetFPS

    WaitForTargetFPS,是关于帧数限制的,你可能开了垂直同步,其实是防止撕裂.先说撕裂,在显示器的帧缓存会被不同步的显卡的帧缓存给替换掉,导致显示器显示到一半的时候,内存被换掉,你看到上频是 ...

  9. codeforces 439D Devu and Partitioning of the Array(有深度的模拟)

    题目 //参考了网上的代码 注意答案可能超过32位 //要达成目标,就是要所有数列a的都比数列b的要小或者等于 //然后,要使最小的要和最大的一样大,就要移动(大-小)步, //要使较小的要和较大的一 ...

  10. POJ 1665

    #include<iostream>//chengdacaizi 08.11.12 #include<iomanip> #define p 3.1415927 using na ...