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 ...
随机推荐
- Number of Containers(数学) 分类: 数学 2015-07-07 23:42 1人阅读 评论(0) 收藏
Number of Containers Time Limit: 1 Second Memory Limit: 32768 KB For two integers m and k, k is said ...
- #include<string.h>
#include<string.h> 1 strcpy #include <string.h> char *strcpy(char *str1, const char *str ...
- ThreadPool(线程池) in .Net
本文来自:http://rickie.cnblogs.com/archive/2004/11/23/67275.html 在多线程的程序中,经常会出现两种情况.一种情况下,应用程序中的线程把大部分的时 ...
- Sharepoint2010 通过 WebFeature 修改web.config
using System;using System.Runtime.InteropServices;using System.Security.Permissions;using Microsoft. ...
- XMLHttpRequest Level 2 使用指南
XMLHttpRequest是一个浏览器接口,使得Javascript可以进行HTTP(S)通信. 最早,微软在IE 5引进了这个接口.因为它太有用,其他浏览器也模仿部署了,ajax操作因此得以诞生. ...
- 利用JQuery实现全选和反选的几种方法
前面介绍了利用JavaScript实现全选功能,其中也有要注意的几点,现在讲解下在JQuery怎么实现全选和反选,下面提供了两种方法实现. 如图:要实现的效果是点击全选框全部选中,再点击全部不选中 方 ...
- 【转载自友盟消息推送iOS文档】在appDelegate中注册推送
1.2 基本功能集成指南 提示 请先在友盟的消息推送管理后台中创建App,获得AppKey和AppSecret 导入SDK 下载 UMessage_Sdk_All_x.x.x.zip并解压缩 导入 ...
- D - Specialized Four-Digit Numbers
Description Find and list all four-digit numbers in decimal notation that have the property that the ...
- IE10以下placeholder不兼容
做页面的时候在谷歌中是显示的,但是换了IE之后总是不显示,一个文本框还好,如果有多个的话,如图: 添加以下一段Jquery代码: <script> var JPlaceHolder = { ...
- oracle中导出导入表以及数据
Oracle数据导入导出imp/exp就相当于oracle数据还原与备份.exp命令可以把数据从远程数据库服务器导出到本地的dmp文件,imp命令可以把dmp文件从本地导入到远处的数据库服务器中.利用 ...