Codeforces Round #245 (Div. 1) B. Working out (dp)
题目:http://codeforces.com/problemset/problem/429/B
第一个人初始位置在(1,1),他必须走到(n,m)只能往下或者往右
第二个人初始位置在(n,1),他必须走到(1,m)只能往上或者往右
每个点都有个权值,要求两个人中间相遇一次且只有一次,相遇的那个点的权值不算,两个人的速度可以不一样,然后求出最大值是多少
思路:他的要求是相遇一次且只有一次,那么画几个图其实就只有两个情况了(这图是借了一位大佬的,【小声bb】)

既然知道了这个图分为了这四个区域,当前格子的其他四个方向的各自都是那个人的必经过点,那么我就求出到那四个方向的最优值是多少,分别用四个dp存储
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#define maxn 1005
#define mod 1000000007
using namespace std;
typedef long long ll;
ll dp1[maxn][maxn];
ll dp2[maxn][maxn];
ll dp3[maxn][maxn];
ll dp4[maxn][maxn];
ll a[maxn][maxn];
ll n,m;
int main()
{
cin>>n>>m;
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
cin>>a[i][j];
}
}
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
dp1[i][j]=max(dp1[i-][j]+a[i][j],dp1[i][j-]+a[i][j]);//左上角开始当起点
}
}
for(int i=;i<=n;i++){
for(int j=m;j>=;j--){
dp2[i][j]=max(dp2[i-][j]+a[i][j],dp2[i][j+]+a[i][j]);//右上角开始当起点
}
}
for(int i=n;i>=;i--){
for(int j=;j<=m;j++){
dp3[i][j]=max(dp3[i+][j]+a[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]+a[i][j],dp4[i][j+]+a[i][j]);//右下角开始当起点
}
}
ll mx=;
for(int i=;i<n;i++){
for(int j=;j<m;j++){
mx=max(mx,max(dp1[i][j-]+dp2[i-][j]+dp3[i+][j]+dp4[i][j+],dp1[i-][j]+dp2[i][j+]+dp3[i][j-]+dp4[i+][j]));//两种状态取最优
}
}
cout<<mx;
}
Codeforces Round #245 (Div. 1) B. Working out (dp)的更多相关文章
- 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 #369 (Div. 2) C. Coloring Trees(dp)
Coloring Trees Problem Description: ZS the Coder and Chris the Baboon has arrived at Udayland! They ...
- Codeforces Round #260 (Div. 1) 455 A. Boredom (DP)
题目链接:http://codeforces.com/problemset/problem/455/A A. Boredom time limit per test 1 second memory l ...
- Codeforces Round #349 (Div. 2) C. Reberland Linguistics (DP)
C. Reberland Linguistics time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Codeforces Round #369 (Div. 2) C. Coloring Trees (DP)
C. Coloring Trees time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Codeforces Round #552 (Div. 3) F. Shovels Shop(dp)
题目链接 大意:给你n个物品和m种优惠方式,让你买k种,问最少多少钱. 思路:考虑dpdpdp,dp[x]dp[x]dp[x]表示买xxx种物品的最少花费,然后遍历mmm种优惠方式就行转移就好了. # ...
- Codeforces Round #367 (Div. 2) B. Interesting drink (模拟)
Interesting drink 题目链接: http://codeforces.com/contest/706/problem/B Description Vasiliy likes to res ...
- Codeforces Round #368 (Div. 2) C. Pythagorean Triples(数学)
Pythagorean Triples 题目链接: http://codeforces.com/contest/707/problem/C Description Katya studies in a ...
- Codeforces Round #275 (Div. 2) C - Diverse Permutation (构造)
题目链接:Codeforces Round #275 (Div. 2) C - Diverse Permutation 题意:一串排列1~n.求一个序列当中相邻两项差的绝对值的个数(指绝对值不同的个数 ...
随机推荐
- 一个可以配置阴影方向和颜色的类 CardView 控件 SCardView
一.控件简述 今天给大家推荐一个控件 SCardView ,看名字就很容易才出来它其实就是一个 CardView .把它拿出来,是因为它解决了一些 CardView 无法实现的需求以及简化了 Card ...
- element-UI表单验证
转载自: 一.简单逻辑验证(直接使用rules) 实现思路 •html中给el-form增加 :rules="rules"•html中在el-form-item 中增加属性 pro ...
- Jmeter转换成中文模式
本片文章转至:https://blog.csdn.net/him2014/article/details/79603887 下载安装好Jmeter后默认的是英文,对于我这种学渣来说简直就是受到了100 ...
- 20190320xlVBA_考场座位设置
花了一写时间做了一个Excel宏工作簿,可以根据考场人数.座位排列和考生名单 生成<考试座位表><考生去向表><考试通知单>,想要的前往了解哦: https://i ...
- SWUST OJ(1038)
顺序表中重复数据的删除 #include <iostream> #include <cstdlib> using namespace std; int main() { int ...
- 老男孩九期全栈Python之基础一
---恢复内容开始--- day1 12.while 体验while的执行方式和效果,用多种方法输出1~100 while 1: print('我们不一样') print('在人间') print(' ...
- CentOS 7中关闭删除virbr0虚拟网卡
[问题] 虚拟机IP:192.168.31.101 本地物理机IP:192.168.31.254 虚拟机安装在本地物理机上 发现问题:本地物理机ping得通虚拟机IP,但是虚拟机无法ping通物理机I ...
- MySQL查询性能优化(精)
MySQL查询性能优化 MySQL查询性能的优化涉及多个方面,其中包括库表结构.建立合理的索引.设计合理的查询.库表结构包括如何设计表之间的关联.表字段的数据类型等.这需要依据具体的场景进行设计.如下 ...
- mock js使用方法简单记录
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- APP包打包签名步骤
开发混合app上架应用市场,需要进行应用签名,但是申请签名如果没搞过,会特别麻烦,所以我自自己总结了一下申请的步骤,在此记录一下 1.首先需要下载安装java环境即jdk, 2.配置环境变量 假设JD ...