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

  1. A Refining Company LightOJ - 1036

    A Refining Company LightOJ - 1036 描述好长啊... 题意:在m*n的矩阵上,每一格摆一个向上或者向左的传送带(不能同时摆,只能摆一个).同时,每一格有两种物资Uran ...

  2. lightoj 1036 - A Refining Company(简单dp)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1036 题解:设dp[i][j]表示处理到(i,j)点时的最大值然后转移显然是 ...

  3. lightoj 1018 dp

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1018 #include <cstdio> #include <cst ...

  4. lightoj 1004 dp:数字三角形

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1004 #include <cstdio> #include <cst ...

  5. URAL 1036(dp+高精度)

    Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Pract ...

  6. loj 1036(dp)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=25913 思路:易证存在一条从左上角到右下角的折线,沿着格子边缘的. ...

  7. lightoj 1013 dp

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1013 #include <cstdio> #include <cst ...

  8. LightOJ 1017 - Brush (III) 记忆化搜索+细节

    http://www.lightoj.com/volume_showproblem.php?problem=1017 题意:给出刷子的宽和最多横扫次数,问被扫除最多的点是多少个. 思路:状态设计DP[ ...

  9. 区间DP LightOJ 1422 Halloween Costumes

    http://lightoj.com/volume_showproblem.php?problem=1422 做的第一道区间DP的题目,试水. 参考解题报告: http://www.cnblogs.c ...

随机推荐

  1. shiro认证

    一.通过ini文件初始化一个用户 1.通过ini配置文件创建securityManager2.调用subject.login方法主体提交认证,提交的token3.securityManager进行认证 ...

  2. window.event对象详细介绍

    1.event代表事件的状态,例如触发event对象的元素.鼠标的位置及状态.按下的键等等.event对象只在事件发生的过程中才有效.event的某些属性只对特定的事件有意义.比如,fromEleme ...

  3. Java学习----finally块

    public class Test { String x; public static void main(String[] args) { Test test = new Test(); try { ...

  4. 彻底弄清c标准库中string.h里的常用函数用法

    在我们平常写的c/c++程序,一些算法题中,我们常常会用到c标准库中string.h文件中的函数,这些函数主要用于处理内存,字符串相关操作,是很有用的工具函数.而且有些时候,在笔试或面试中也会出现让你 ...

  5. TensorFlow和最近发布的slim

    笔者将和大家分享一个结合了TensorFlow和最近发布的slim库的小应用,来实现图像分类.图像标注以及图像分割的任务,围绕着slim展开,包括其理论知识和应用场景. 之前自己尝试过许多其它的库,比 ...

  6. 《python源码剖析》笔记一——python编译

    1.python的架构: 2.python源码的组织结构: 3.windows环境下编译python:

  7. JS实现继承多态

    //类对象构造模版,无new访问,类似静态访问 var Class = { create: function () { return function () { //initialize初始化 //a ...

  8. 为何要fork()两次来避免产生僵尸进程??

    最近安装书上说的,开始搞多进程了..看到了一个好帖子,学习学习 http://blog.sina.com.cn/s/blog_9f1496990100y420.html 首先我们要明白,为什么要避免僵 ...

  9. Bridage

    对于有两个以上的维度的对象,如下图:这张图的业务逻辑是这样的,Hayes,USR以及Emie都是上网的猫,现在有两条线路,一条是传统Dial,还有一条线路是专线,不需要拨号,这样每创建一种线路就意味着 ...

  10. 横向浅谈移动技术------( 原生,混合,web --- 谁能问鼎移动开发的明天)

    目前移动互联网基本采用了NativeApp.WebApp.HybridApp三种开发模式,很难说这三种模式那种更优越,目前的情况可以说是三分天下吧,不同的开发者可以根据自己的实际情况选择不同的开发模式 ...