题目链接: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. 给右键 添加dos命令

    reg add "HKEY_CURRENT_USER\Console" /v "ScreenBufferSize" /t REG_DWORD /d 655361 ...

  2. C语言运算符与表达式

    1 概论 计算机内存中的数据可以通过变量,常量来表示和存储,那么这些数据如何运算? C语言中提供了大量(34种)的运算符可以用来完成数据的算术,赋值,逻辑,关系,条件判断以及自增自减运算和基于二进制的 ...

  3. Win32中GDI+应用(二)--初始化与清理

    GDI+提供了GdiplusStartup和 GdiplusShutdown 函数来进行初始化和完成清理工作.你必须在调用其他的GDI+函数之前,调用GdiplusStartup函数,在完成GDI+工 ...

  4. Windows phone常用控件之Button

    Button类:表示一个响应 ButtonBase.Click 事件的 Windows 按钮控件. 继承层次结构: 命名空间:    System.Windows.Controls ClickMode ...

  5. mws文件中的tab文件改为相对路径

    用mapinfo将现有的多个图层(tab)文件保存成一个mws工作空间后,将此mws文件发到另一台电脑上后,打开mws,提示无法打开各个tab文件,文件不存在,显示的路径是当时原电脑添加时的绝对路径. ...

  6. [Linux]ubuntu安装ftp服务器

     1: 安装vsftpd~$ sudo apt-get install vsftpd  or~$ yum install vsftpd温馨提示:ubuntu10.10自己装了,这步省略. 2: 配置v ...

  7. quick-x 触摸事件的新方法

    --[[ local function onTouch(event, x, y) print(event, x, y) if event == "began" then retur ...

  8. dedecms织梦如何删除所有的文章?

    dedecms织梦如何删除所有的文章?dede一键删除所有文章的SQL命令:  DELETE FROM dede_addonarticle WHERE aid >= 1 and aid<= ...

  9. Android 简单的FC

    直接贴log 01-02 08:17:56.589 I/ActivityManager( 312): Start proc com.android.providers.calendar for con ...

  10. POJ 3041 Asteroids 最小点覆盖 == 二分图的最大匹配

    Description Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape o ...