LightOJ 1004 - Monkey Banana Problem (dp)
来源:互联网 发布:c语言if语句嵌套的规定 编辑:程序博客网 时间:2024/05/16 18:09
题意: 变形数塔
分析: 水题 - - 注意边界, 然后开大数组可以无视
代码:
//// Created by TaoSama on 2015-10-27// Copyright (c) 2015 TaoSama. All rights reserved.////#pragma comment(linker, "/STACK:1024000000,1024000000")#include <algorithm>#include <cctype>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iomanip>#include <iostream>#include <map>#include <queue>#include <string>#include <set>#include <vector>using namespace std;#define pr(x) cout << #x << " = " << x << " "#define prln(x) cout << #x << " = " << x << endlconst int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;typedef long long LL;int n, a[205][205], dp[205][205];void getMax(int &x, int y) {x = max(x, y);}int main() {#ifdef LOCAL freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin);// freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout);#endif ios_base::sync_with_stdio(0); int t; scanf("%d", &t); int kase = 0; while(t--) { scanf("%d", &n); memset(a, 0, sizeof a); for(int i = 1, cnt = 0; i < n << 1; ++i) { cnt += i <= n ? 1 : -1; for(int j = 1; j <= cnt; ++j) scanf("%d", &a[i][j]); } memset(dp, 0, sizeof dp); for(int i = 1, cnt = 1; i < n << 1; ++i) { int x = i <= n ? 1 : -1; cnt += x; for(int j = 1; j <= cnt; ++j) { getMax(dp[i][j], dp[i - 1][j] + a[i][j]); getMax(dp[i][j], dp[i - 1][j - x] + a[i][j]); } } printf("Case %d: %d\n", ++kase, dp[(n << 1) - 1][1]); } return 0;}
0 0
- LightOJ 1004 - Monkey Banana Problem (dp)
- LightOJ 1004 - Monkey Banana Problem(dp)
- LightOJ 1004 - Monkey Banana Problem 【DP】
- LightOJ - 1004 Monkey Banana Problem(DP)
- lightoj 1004 - Monkey Banana Problem 【dp】
- LightOJ-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
- lightoj 1004 - Monkey Banana Problem
- LightOJ 1004 Monkey Banana Problem
- LightOJ 1004 Monkey Banana Problem (线性dp 数字菱形)
- LightOJ 1004 Monkey Banana Problem (DP 数字三角形)
- 1004 - Monkey Banana Problem (dp)
- LightOJ 1004 Monkey Banana Problem 动态规划
- 【DP】 Light OJ 1004 Monkey Banana Problem
- Hibernate 、继承关联映射
- cocos2d-x getBoundingBox getContentSize getTextureRect 解释
- java怎么还是那么渣O(∩_∩)O哈哈~Class,Object这些混淆的概念
- jQuery 中 attr() 和 prop() 方法的区别
- Map<String, String> 遍历的四种方法
- LightOJ 1004 - Monkey Banana Problem (dp)
- Unity3D Shader 开发详解 (1)
- Linux下Socket的实现(C++)
- codeblocks round 326 div2 C Duff and Weight Lifting
- hdoj--1166--敌兵布阵(线段树)
- unity中使用protobuf(兼容ios平台)
- EXT.js对中文字符串的排序
- awk 数组
- 调试程序 识别线程 用QThread::currentThread()方法