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.求一个序列当中相邻两项差的绝对值的个数(指绝对值不同的个数 ...
随机推荐
- 修改Ubuntu锁屏快捷键
修改为Win + L. 避免与Phpstorm中的代码格式化冲突.
- English trip EM1 - PE2 My My name is... Teacher:Lamb Key: introduce myself
课上内容(Lesson) Lamb let us does introduce myself. Make a "hangman" game at warm-up . How to ...
- postgis 随笔
一.表的定义: 对于任何一种关系型数据库而言,表都是数据存储的最核心.最基础的对象单元.现在就让我们从这里起步吧. 1. 创建表: CREATE TABLE products ( ...
- scikit_learn lasso详解
Lasso 回归 l1 正则化 The Lasso 是估计稀疏系数的线性模型. 它在一些情况下是有用的,因为它倾向于使用具有较少参数值的情况,有效地减少给定解决方案所依赖变量的数量. 因此,Lasso ...
- Python面向对象编程 -- 类和实例、访问限制
面向对象编程 Object Oriented Programming,简称OOP,是一种程序设计思想.OOP把对象作为程序的基本单元,一个对象包含了数据和操作数据的函数. 面向过程的程序设计把计算机程 ...
- 思科模拟器PacketTracer7-----2台PC通过交叉线互连
实验二—3 实验工具:思科模拟器PacketTracer7(可在思科官网下载,免费) 实验设备: PC两台,交叉线 实验步骤: 一.配置网络拓扑图 二.配置PC0和PC1的IP地址,掩码和网关 四.通 ...
- nodeJs安装Vue-cli
1,安装nodejs安装包,注意安装的路径 2,安装完成node,node有自带的npm,可以直接在cmd中,找到nodeJs安装的路径下,进行命令行全局安装vue-cli.(npm install ...
- Shell 脚本练习
[第一个] #!/bin/bash#每个用户的总充值和消费以及剩余. cat yuanbao.txt |grep -v 2016 |awk '{print $3}' |awk '!a[$0]++' & ...
- 2018 HDU多校第四场赛后补题
2018 HDU多校第四场赛后补题 自己学校出的毒瘤场..吃枣药丸 hdu中的题号是6332 - 6343. K. Expression in Memories 题意: 判断一个简化版的算术表达式是否 ...
- elasticSearch安装 Kibana安装 Sense安装
安装最新版本,安装6.*版本 先提示一个重要的事情,kibana新版本不需要安装Sense, 官方的是老版的Kibana才需要,我们现在用devTool http://localhost:5601/a ...