lightoj 1036 dp
题目链接:http://lightoj.com/volume_showproblem.php?problem=1036
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std; const int maxn = ; int m,n;
int dp[maxn][maxn][];
int leftsum[maxn][maxn],upsum[maxn][maxn]; int main()
{
//freopen("E:\\acm\\input.txt","r",stdin);
int T;
cin>>T;
for(int cas=;cas<=T;cas++){
cin>>m>>n;
for(int i=;i<=m;i++) upsum[][i] = ;
for(int i=;i<=n;i++) leftsum[i][] = ;
for(int i=;i<=m;i++)
for(int j=;j<=n;j++){
int a;
scanf("%d",&a);
leftsum[i][j] = leftsum[i][j-] + a;
}
for(int i=;i<=m;i++)
for(int j=;j<=n;j++){
int a;
scanf("%d",&a);
upsum[i][j] = upsum[i-][j] + a;
}
memset(dp,,sizeof(dp));
for(int sum=;sum<=m+n;sum++){
for(int i=;i<=sum-;i++){
int j = sum - i;
if(i>m || j>n) continue;
dp[i][j][] = max(dp[i][j-][],dp[i][j-][]) + upsum[i][j];
dp[i][j][] = max(dp[i-][j][],dp[i-][j][]) + leftsum[i][j];
}
}
int ans = max(dp[m][n][],dp[m][n][]);
printf("Case %d: %d\n",cas,ans);
}
}
lightoj 1036 dp的更多相关文章
- A Refining Company LightOJ - 1036
A Refining Company LightOJ - 1036 描述好长啊... 题意:在m*n的矩阵上,每一格摆一个向上或者向左的传送带(不能同时摆,只能摆一个).同时,每一格有两种物资Uran ...
- lightoj 1036 - A Refining Company(简单dp)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1036 题解:设dp[i][j]表示处理到(i,j)点时的最大值然后转移显然是 ...
- lightoj 1018 dp
题目链接:http://lightoj.com/volume_showproblem.php?problem=1018 #include <cstdio> #include <cst ...
- lightoj 1004 dp:数字三角形
题目链接:http://lightoj.com/volume_showproblem.php?problem=1004 #include <cstdio> #include <cst ...
- URAL 1036(dp+高精度)
Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status Pract ...
- loj 1036(dp)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=25913 思路:易证存在一条从左上角到右下角的折线,沿着格子边缘的. ...
- lightoj 1013 dp
题目链接:http://lightoj.com/volume_showproblem.php?problem=1013 #include <cstdio> #include <cst ...
- LightOJ 1017 - Brush (III) 记忆化搜索+细节
http://www.lightoj.com/volume_showproblem.php?problem=1017 题意:给出刷子的宽和最多横扫次数,问被扫除最多的点是多少个. 思路:状态设计DP[ ...
- 区间DP LightOJ 1422 Halloween Costumes
http://lightoj.com/volume_showproblem.php?problem=1422 做的第一道区间DP的题目,试水. 参考解题报告: http://www.cnblogs.c ...
随机推荐
- linux rman shell
# make direcory for backset file and scripts file,in my case /backup/db_bak cd /backup/db_bak mkdi ...
- Codeforces 553D Nudist Beach(图论,贪心)
Solution: 假设已经选了所有的点. 如果从中删掉一个点,那么其它所有点的分值只可能减少或者不变. 如果要使若干步删除后最小的分值变大,那么删掉的点集中肯定要包含当前分值最小的点. 所以每次删掉 ...
- sae的kvdb使用注意
之前没仔细看,原来sae的kvdb使用一定要先调用初始化函数 $kv = new SaeKV(); $kv->init();//必须使用 $kv->set('index', $data);
- Android 进程和文件的UID/GID
一.文件的操作权限和UID,GID以及进程的UID,GID 1. 文件资源的权限力度:UID/GID 2. 文件的可操作权限 3. 进程的标识: PID, UID, GID, GIDs 二.UID,G ...
- WPF之Treeview控件简单用法
TreeView:表示显示在树结构中分层数据具有项目可展开和折叠的控件 TreeView 的内容是可以包含丰富内容的 TreeViewItem 控件,如 Button 和 Image 控件.TreeV ...
- The largest prime factor(最大质因数)
1. 问题: The prime factors of 13195 are 5, 7, 13 and 29.What is the largest prime factor of the number ...
- 《Zero to One》的一些读书笔记
第一章<The Challenge of the Future>:全球化是横向的扩张,只能复制以前就有的成功,而科技创新是纵向的扩张,是创造以前不存在的东西.没有科技创新,只有全球化,这个 ...
- CSS实现文字竖排 DIV CSS文字垂直竖列排版显示如何实现?
DIV CSS实现文字竖排排版显示兼容各大浏览器,让文字垂直竖列排版布局. 有时我们需要一段文字进行从上到下竖列排版,我们知道CSS样式中有一样式可以让其竖列排版,但所有浏览器不全兼容,逼不得已放弃. ...
- leetcode面试准备:Decode Ways
1 题目 A message containing letters from A-Z is being encoded to numbers using the following mapping: ...
- 精确到时分秒的jQuery插件例子
demo.html: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type&q ...