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 ...
随机推荐
- CoreAnimation5-图层时间和缓冲
图层时间 动画的发生是需要持续一段时间的,所以计时对整个概念来说至关重要.在这一章中,我们来看看CAMediaTiming,看看Core Animation是如何跟踪时间的. CAMediaTimin ...
- c语言中文件相关操作
一 .首先介绍一下数据文件的类型: 1.二进制文件(映像文件):在内存中以二进制形式存取. 2.文本文件(ascii文件):以ascii码形式存取的文件. 通俗的讲,在Mac下,你把一个文件丢进记事本 ...
- wireshark添加用户执行
默认情况下,访问网络端口需要root权限,而wireshark的只是/usr/share/dumpcap的一个UI,/usr/share/dumpcap需要root权限,所以没法non-root用户无 ...
- CentOS 6.4 64位 安装 apache-tomcat-6.0.43
下载 tomcat: 地址:http://mirrors.hust.edu.cn/apache/tomcat/tomcat-6/v6.0.43/bin/apache-tomcat-6.0.43.tar ...
- 对象序列化XML
/// <summary>/// 对象序列化XML/// </summary>/// <param name="type">类型</par ...
- C# 获取路径中文件名、目录、扩展名等
string path = "C:\\dir1\\dir2\\foo.txt"; string str = "GetFullPath:" + Path.GetF ...
- 聊一聊c++中指针为空的三种写法 ----->NULL, 0, nullptr
看到同事用了一下nullptr.不是很了解这方面东东,找个帖子学习学习 http://www.cppblog.com/airtrack/archive/2012/09/16/190828.aspx N ...
- sql update from 修改一个表的值来自另一个表
假设有桌子表名 icate_table_set(table_id,table_name,table_state_id,store_id), 桌子状态表名icate_table_state(state_ ...
- 十六进制字符串转化为byte数组
工作上有这样的需求之前找了好多都不行,好不容易有个可以的赶紧留下来. 原址:http://blog.163.com/roadwalker@126/blog/static/113561841201013 ...
- POOL
#ifndef POOL_HHH #define POOL_HHH #include "common.h" /* simple and fast obj pool without ...