Codeforces Round #245 (Div. 1)——Working out
- 题意:
一个n*m的矩阵,每一个方格有一个非负数,如今选择两条线路:一个左上到右下,一个左下到右上,且仅仅能有一个公共点。求两个线路上数的最大值(公共点不算)
- 分析:
仅仅有两种情况,dp就可以。记两个线路为1和2。考虑一个公共点。1为左进右出。2为下进上出。1上进下出,2为左进右出
const int MAXN = 1005; int lu[MAXN][MAXN], ld[MAXN][MAXN];
int ru[MAXN][MAXN], rd[MAXN][MAXN];
int ipt[MAXN][MAXN];
int n, m; int main()
{
// freopen("in.txt", "r", stdin);
while (~RII(n, m))
{
CLR(ipt, -1);
FE(i, 1, n) FE(j, 1, m) RI(ipt[i][j]);
lu[1][1] = ipt[1][1];
ru[1][m] = ipt[1][m];
ld[n][1] = ipt[n][1];
rd[n][m] = ipt[n][m]; FE(i, 1, n) FE(j, 1, m)
{
lu[i][j + 1] = max(lu[i][j + 1], lu[i][j] + ipt[i][j + 1]);
lu[i + 1][j] = max(lu[i + 1][j], lu[i][j] + ipt[i + 1][j]);
}
FE(i, 1, n) FED(j, m, 1)
{
ru[i][j - 1] = max(ru[i][j - 1], ru[i][j] + ipt[i][j - 1]);
ru[i + 1][j] = max(ru[i + 1][j], ru[i][j] + ipt[i + 1][j]);
}
FED(i, n, 1) FE(j, 1, m)
{
ld[i][j + 1] = max(ld[i][j + 1], ld[i][j] + ipt[i][j + 1]);
ld[i - 1][j] = max(ld[i - 1][j], ld[i][j] + ipt[i - 1][j]);
}
FED(i, n, 1) FED(j, m, 1)
{
rd[i][j - 1] = max(rd[i][j - 1], rd[i][j] + ipt[i][j - 1]);
rd[i - 1][j] = max(rd[i - 1][j], rd[i][j] + ipt[i - 1][j]);
}
int ans = 0;
FE(i, 1, n) FE(j, 1, m)
{
if (i - 1 >= 1 && j - 1 >= 1 && i + 1 <= n && j + 1 <= m)
{
ans = max(ans, lu[i - 1][j] + ld[i][j - 1] + rd[i + 1][j] + ru[i][j + 1]);
}
if (j - 1 >= 1 && i + 1 <= n && j + 1 <= m && i - 1 >= 1)
{
ans = max(ans, lu[i][j - 1] + ld[i + 1][j] + rd[i][j + 1] + ru[i - 1][j]);
}
}
WI(ans);
}
return 0;
}
Codeforces Round #245 (Div. 1)——Working out的更多相关文章
- Codeforces Round #245 (Div. 1) 429D - Tricky Function 最近点对
D. Tricky Function Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 codeforces.com/problemset/problem/42 ...
- Codeforces Round #245 (Div. 1) B. Working out (简单DP)
题目链接:http://codeforces.com/problemset/problem/429/B 给你一个矩阵,一个人从(1, 1) ->(n, m),只能向下或者向右: 一个人从(n, ...
- Codeforces Round #245 (Div. 1) B. Working out (dp)
题目:http://codeforces.com/problemset/problem/429/B 第一个人初始位置在(1,1),他必须走到(n,m)只能往下或者往右 第二个人初始位置在(n,1),他 ...
- Codeforces Round #245 (Div. 1) B. Working out dp
题目链接: http://codeforces.com/contest/429/problem/B B. Working out time limit per test2 secondsmemory ...
- Codeforces Round #245 (Div. 2) C. Xor-tree DFS
C. Xor-tree Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/430/problem/C ...
- Codeforces Round #245 (Div. 2) B. Balls Game 并查集
B. Balls Game Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/430/problem ...
- Codeforces Round #245 (Div. 2) A. Points and Segments (easy) 贪心
A. Points and Segments (easy) Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/con ...
- Codeforces 429 B. Working out-dp( Codeforces Round #245 (Div. 1))
B. Working out time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- Codeforces Round #245 (Div. 2) B - Balls Game
暴利搜索即可 #include <iostream> #include <vector> #include <iostream> using namespace s ...
- Codeforces Round #245 (Div. 2) A - Points and Segments (easy)
水到家了 #include <iostream> #include <vector> #include <algorithm> using namespace st ...
随机推荐
- C#静态构造函数和析构函数片段化认知
一.静态构造函数 一个类可以有静态构造函数,实现如下源代码.静态构造函数有以下特性: 1).静态构造函数不能有修饰符(润饰符) 2).静态构造函数不能有参数 3).不能被调用——在实例化类的时候,静态 ...
- Letter of application, e-mail version
Subject line: (logical to recipient!) Application for sales representative for mid-Atlantic area Apr ...
- Asp.net MVC5中Html.DropDownList的使用
一.静态下拉列表项的绑定 在下拉列表中绑定静态项,我们可以通过 SelectListItem 的集合作为数据源的下拉列表. @Html.DropDownList("dropRoles&quo ...
- [转]WCF:如何将net.tcp协议寄宿到IIS
本文转自:http://www.cnblogs.com/Gyoung/archive/2012/12/11/2812555.html 1 部署IIS 1.1 安装WAS IIS原本是不支持非HTTP协 ...
- Java中使用webservice,简化开发(xfire的webservice)
首先,使用到的jar先导入项目中, xbean-spring-2.8.jar, wsdl4j-1.6.1.jar, commons-httpclient-3.0.jar, commons-codec- ...
- mvc ajax请求
@{ ViewBag.Title = "ajax"; } <script src="../../Scripts/jquery-1.4.4.js" type ...
- 给小班讲stl 之 map、sort、优先队列
引子:最近老师让给小班讲课,讲stl,,但是我觉得就小班现在这水平根本讲不懂好不好,,,,
- delphi access中SQL根据时间查询
Access数据库虽然功能是差了点,但是有时对一些少量的数据保存很是很方便的,在delphi中也是如此,在查询时免不了要按照日期或 时间作为查询条件,access有些特别. select * from ...
- Java并发编程之ThreadLocal类
ThreadLocal类可以理解为ThreadLocalVariable(线程局部变量),提供了get与set等访问接口或方法,这些方法为每个使用该变量的线程都存有一份独立的副本,因此get总是返回当 ...
- %hd %d %ld %u ......
%d 有符号10进制整数 %ld 长整型 %hd短整型%md,m指定的是输出字段的宽度,默认左补空格, 如果数据的位数小于m,则左端补以空格,若大于m,则 按实际位数输出,如: printf(&quo ...