Codeforces Round #245 (Div. 1) B. Working out (简单DP)
题目链接:http://codeforces.com/problemset/problem/429/B
给你一个矩阵,一个人从(1, 1) ->(n, m),只能向下或者向右; 一个人从(n, 1) ->(1, m),只能向上或者向右。必须有一个相遇点, 相遇点的值不能被取到, 问两个人能得到的最大路径和是多少?
dp[i][j]:表示从一个点出发的最大值;先预处理从(1,1) (1,m) (n,1) (n,m)四个点出发的4个dp最大值。然后枚举所有的点,但是这个点不能在边缘,考虑枚举点不够,还要考虑枚举这个点的上下左右的值。
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + ;
int dp1[MAXN][MAXN] , dp2[MAXN][MAXN] , dp3[MAXN][MAXN] , dp4[MAXN][MAXN];
int a[MAXN][MAXN]; int main()
{
int n , m;
scanf("%d %d" , &n , &m);
for(int i = ; i <= n ; ++i) {
for(int j = ; j <= m ; ++j) {
scanf("%d" , &a[i][j]);
}
}
for(int i = ; i <= n ; ++i) {
for(int j = ; j <= m ; ++j) {
dp1[i][j] = max(dp1[i - ][j] , dp1[i][j - ]) + a[i][j];
}
}
for(int i = n ; i >= ; --i) {
for(int j = ; j <= m ; ++j) {
dp2[i][j] = max(dp2[i + ][j] , dp2[i][j - ]) + a[i][j];
}
}
for(int i = ; i <= n ; ++i) {
for(int j = m ; j >= ; --j) {
dp3[i][j] = max(dp3[i][j + ] , dp3[i - ][j]) + a[i][j];
}
}
for(int i = n ; i >= ; --i) {
for(int j = m ; j >= ; --j) {
dp4[i][j] = max(dp4[i + ][j] , dp4[i][j + ]) + a[i][j];
}
}
int res = ;
for(int i = ; i < n ; ++i) {
for(int j = ; j < m ; ++j) {
res = max(res , dp1[i][j - ] + dp2[i + ][j] + dp3[i - ][j] + dp4[i][j + ]);
res = max(res , dp1[i - ][j] + dp2[i][j - ] + dp3[i][j + ] + dp4[i + ][j]);
}
}
printf("%d\n" , res);
return ;
}
Codeforces Round #245 (Div. 1) B. Working out (简单DP)的更多相关文章
- Codeforces Round #302 (Div. 2) C. Writing Code 简单dp
C. Writing Code Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/544/prob ...
- Codeforces Round #245 (Div. 1) B. Working out (dp)
题目:http://codeforces.com/problemset/problem/429/B 第一个人初始位置在(1,1),他必须走到(n,m)只能往下或者往右 第二个人初始位置在(n,1),他 ...
- Codeforces Round #369 (Div. 2) C. Coloring Trees(简单dp)
题目:https://codeforces.com/problemset/problem/711/C 题意:给你n,m,k,代表n个数的序列,有m种颜色可以涂,0代表未涂颜色,其他代表已经涂好了,连着 ...
- Codeforces Round #367 (Div. 2) C. Hard problem(DP)
Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...
- 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/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 ...
随机推荐
- 使用easyui实现列表的批量删除
使用easyui实现列表的批量删除 首先要做的就是增加一个多选框 <table id="otGrid" nowrap="false" style=&quo ...
- VB VS2003获取当前进程用户登录
Page.User.Identity.Name获取当前进程用户名称,VS03才可以用
- bzoj3798: 特殊的质数
分块打表.块内的暴力块外的打表.开始没有j>0所以WA了. #include<cstdio> #include<cmath> #include<cstring> ...
- Ajax、Comet与Websocket
从 http 协议说起 1996年IETF HTTP工作组发布了HTTP协议的1.0版本 ,到现在普遍使用的版本1.1,HTTP协议经历了17 年的发展.这种分布式.无状态.基于TCP的请求/响应式 ...
- VS2010安装中遇到的错误
背景 用win7 64位系统安装VS2010遇到一个错误,网上查了各种资料也没有找到这种解决办法,后来自己找到了解决办法,分享一下,让他人少走一些弯路. 错误信息 安装过程中遇到如下错误: [08/2 ...
- Web API入门指南(安全)转
安全检测的工具站点:https://www.owasp.org/index.php/Category:Vulnerability_Scanning_Tools Web API入门指南有些朋友回复问了些 ...
- Darwin Streaming Server Relay Setting
安装完Darwin Streaming Server,就可以使用VLC通过RTSP协议播放流媒体文件了.但是我现在有一个需求,需要将一台DSS(假设为A机)上的媒体文件发送到另一台DSS(假设为B机) ...
- android和ios流媒体库推荐
1基本信息编辑 Vitamio是一款 Android 与 iOS 平台上的全能多媒体开发框架,全面支持硬件解码与 GPU 渲染.从2011年8月上线到2014年1月,Vitamio 凭借其简洁易用的 ...
- win7/8下VirtualBox虚拟共享文件夹设置
1. 安装增强功能包(VBoxGuestAdditions) 打开虚拟机,运行ubuntu,在菜单栏选择"设备->安装增强功能",根据提示即可安装成功(成功后也可 以实现 ...
- 解决:Unable to connect to repository https://dl-ssl.google.com/android/eclipse/site.xml
ailed to fectch URl https://dl-ssl.google.com/android/repository/addons_list.xml, reason: Connection ...