【链接】 我是链接,点我呀:)

【题意】

两个人,一个人在左上角,一个人在左下角。
左上角要到右下角去
左下角要到右上角去
只能走到相邻的格子(不能往回走,即一个往右下,一个往右上走)
要求这两个人必须要在这个n*m的格子中选择一个格子作为休息点.
(两条路径只能有一个一样的点)
问最多能拿到多少分数(每个格子上有一个分数值)

【题解】

![](https://img2018.cnblogs.com/blog/1251265/201902/1251265-20190214171159886-1414539422.png)
会发现只有②和③不会重复走
则设f[p][i][j]分别为从左上、左下、右上、右下出发,到达点(i,j)的最大分数值
枚举休息点在什么地方
根据上图取答案的最大值就好

【代码】

import java.io.*;
import java.util.*; public class Main { static InputReader in;
static PrintWriter out; public static void main(String[] args) throws IOException{
//InputStream ins = new FileInputStream("E:\\rush.txt");
InputStream ins = System.in;
in = new InputReader(ins);
out = new PrintWriter(System.out);
//code start from here
new Task().solve(in, out);
out.close();
} static int N = (int)1e3;
static class Task{
public void solve(InputReader in,PrintWriter out) {
int n,m;
int [][]a = new int[N+10][N+10];
int [][][]f = new int[4][N+10][N+10];
n = in.nextInt();m = in.nextInt();
for (int i = 1;i <= n;i++)
for (int j = 1;j <= m;j++)
a[i][j] = in.nextInt(); //f[0]
for (int i = 1;i <= n;i++)
for (int j = 1;j <= m;j++)
f[0][i][j] = Math.max(f[0][i-1][j], f[0][i][j-1])+a[i][j]; //f[1]
for (int i = 1;i <= n;i++)
for (int j = m;j >= 1;j--)
f[1][i][j] = Math.max(f[1][i-1][j], f[1][i][j+1])+a[i][j]; //f[2]
for (int i = n;i >= 1;i--)
for (int j = 1;j <= m;j++)
f[2][i][j] = Math.max(f[2][i][j-1], f[2][i+1][j])+a[i][j]; //f[3]
//f[0]
for (int i = n;i >= 1;i--)
for (int j = m;j >= 1;j--)
f[3][i][j] = Math.max(f[3][i+1][j], f[3][i][j+1])+a[i][j]; int ans = 0;
for (int i = 1;i <= n;i++)
for (int j = 1;j <= m;j++) {
//(i,j)
if (i>=2 && i<=n-1 && j>=2 && j <= m-1) {
//plan 2
int temp0,temp1,temp2,temp3;
temp0 = f[0][i-1][j];
temp1 = f[1][i][j+1];
temp2 = f[2][i][j-1];
temp3 = f[3][i+1][j];
ans = Math.max(ans, temp0+temp1+temp2+temp3); //plan 3
temp0 = f[0][i][j-1];
temp1 = f[1][i-1][j];
temp2 = f[2][i+1][j];
temp3 = f[3][i][j+1];
ans = Math.max(ans, temp0+temp1+temp2+temp3);
}
}
out.println(ans);
}
} static class InputReader{
public BufferedReader br;
public StringTokenizer tokenizer; public InputReader(InputStream ins) {
br = new BufferedReader(new InputStreamReader(ins));
tokenizer = null;
} public String next(){
while (tokenizer==null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(br.readLine());
}catch(IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
} public int nextInt() {
return Integer.parseInt(next());
}
}
}

【Codeforces 429B】Working out的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  3. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  4. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  5. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  6. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  7. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

  8. 【Codeforces 670C】 Cinema

    [题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...

  9. 【codeforces 515D】Drazil and Tiles

    [题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...

随机推荐

  1. ALSA声卡驱动中的DAPM详解之六:精髓所在,牵一发而动全身

    设计dapm的主要目的之一,就是希望声卡上的各种部件的电源按需分配,需要的就上电,不需要的就下电,使得整个音频系统总是处于最小的耗电状态,最主要的就是,这一切对用户空间的应用程序是透明的,也就是说,用 ...

  2. 单纯形&&线性规划

    沦为了背板子...wyfcyx的ppt #include<bits/stdc++.h> using namespace std; ; , inf = 1e18; int n, m, l, ...

  3. bzoj1121[POI2008]激光发射器SZK(结论)

    1121: [POI2008]激光发射器SZK Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 916  Solved: 759[Submit][Sta ...

  4. 互斥的数(hash)

    1553 互斥的数  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold     题目描述 Description 有这样的一个集合,集合中的元素个数由给定的N决定, ...

  5. cogs750栅格网络流(最小割)

    750. 栅格网络流 ★★☆   输入文件:flowa.in   输出文件:flowa.out   简单对比时间限制:1 s   内存限制:128 MB [问题描述] Bob 觉得一般图的最大流问题太 ...

  6. [Swift通天遁地]六、智能布局-(6)其他几种约束关系:父视图/Corner/Edge/AnchorAndFillEdge

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  7. win快速搜索软件

    Everything 与其他搜索工具的简单比较: Everything 是至今为止 X-Force 所使用过速度最快的文件搜索工具.与它相似的有异次元曾经介绍过一款很老的软件AVAFind,也非常的优 ...

  8. SPOJ 1811 SAM 初探

    思路: 一个串建SAM 另一个串在SAM上跑 //By SiriusRen #include <cstdio> #include <cstring> #include < ...

  9. ACM_Alien And Password

    Alien And Password Time Limit: 2000/1000ms (Java/Others) Problem Description: Alien Fred wants to de ...

  10. [转]linux之磁盘配额(quota)

    转自:http://www.jb51.net/LINUXjishu/78446.html 磁盘配额(quota)比较常用的几个情况是: * 针对WWW server,例如:每个人的网页空间的容量限制 ...