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.求一个序列当中相邻两项差的绝对值的个数(指绝对值不同的个数 ...
随机推荐
- css复合选择器的权重
选择器的权重 标签选择器的权重为0001 class选择器的权重为0010 id选择器的权重为0100 属性选择器的权重为0010 伪类选择器的权重为0010 伪元素选择器的权重为0010 包含选择器 ...
- IntelliJ IDEA 和 Pycharm 破解
关键网址:http://idea.lanyus.com/ 步骤: 1. 在http://idea.lanyus.com/上下载:JetbrainsCrack-2.9-release-enc.jar . ...
- spring cloud 初体验
spring cloud分为注册端.客户端以及消费端 初体验的理解就是: 注册端就是将之前所有的应用在这边进行注册,然后给每个应用都生成自己的标识,这些应用就是来自于客户端,消费端则通过调用注册端(有 ...
- JVM-GC学习
http://blog.csdn.net/column/details/14851.html 地址记录
- springboot访问数据库(MySql)
1.使用JDBC访问数据库:JDBC是用于在Java语言编程中与数据库连接的API <dependency> <groupId>org.springframework.boot ...
- Disable access to Windows Update
Disable access to Windows Update If this policy setting is enabled, all Windows Update features are ...
- shell脚本中gsub的应用
(1)文件filename的内容 cat awk_file 1 2 3 $1,200.00 1 2 3 $2,300.00 1 2 3 $4,000.00 (2)去掉第四列的$和,并汇总第四列的和 a ...
- java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context 错误
spring boot 项目启动报错:原因一般是注入了相同名字的service -- :: com.gxcards.mes.MainWwwWeb: logStartupProfileInfo INFO ...
- h5软键盘弹起 底部按钮被顶起问题解决
解决思路: 当键盘弹起时隐藏掉按钮,键盘隐藏时按钮显示 监测键盘是否弹起(浏览器页面是否发生变化) 代码: 1.定义一个底部按钮 <div class="returnbtn" ...
- centos7上keepalived的安装和配置
1.环境规划1)master:node1,centos7.5,eth0:192.168.1.11,eht1:10.10.1.11,keepalive2)backup:node1,centos7.5,e ...