题目链接

  • 题意:

    一个n*m的矩阵,每一个方格有一个非负数,如今选择两条线路:一个左上到右下,一个左下到右上,且仅仅能有一个公共点。

    求两个线路上数的最大值(公共点不算)

  • 分析:

    仅仅有两种情况,dp就可以。

    记两个线路为1和2。考虑一个公共点。1为左进右出。2为下进上出。1上进下出,2为左进右出

const int MAXN = 1005;

int lu[MAXN][MAXN], ld[MAXN][MAXN];
int ru[MAXN][MAXN], rd[MAXN][MAXN];
int ipt[MAXN][MAXN];
int n, m; int main()
{
// freopen("in.txt", "r", stdin);
while (~RII(n, m))
{
CLR(ipt, -1);
FE(i, 1, n) FE(j, 1, m) RI(ipt[i][j]);
lu[1][1] = ipt[1][1];
ru[1][m] = ipt[1][m];
ld[n][1] = ipt[n][1];
rd[n][m] = ipt[n][m]; FE(i, 1, n) FE(j, 1, m)
{
lu[i][j + 1] = max(lu[i][j + 1], lu[i][j] + ipt[i][j + 1]);
lu[i + 1][j] = max(lu[i + 1][j], lu[i][j] + ipt[i + 1][j]);
}
FE(i, 1, n) FED(j, m, 1)
{
ru[i][j - 1] = max(ru[i][j - 1], ru[i][j] + ipt[i][j - 1]);
ru[i + 1][j] = max(ru[i + 1][j], ru[i][j] + ipt[i + 1][j]);
}
FED(i, n, 1) FE(j, 1, m)
{
ld[i][j + 1] = max(ld[i][j + 1], ld[i][j] + ipt[i][j + 1]);
ld[i - 1][j] = max(ld[i - 1][j], ld[i][j] + ipt[i - 1][j]);
}
FED(i, n, 1) FED(j, m, 1)
{
rd[i][j - 1] = max(rd[i][j - 1], rd[i][j] + ipt[i][j - 1]);
rd[i - 1][j] = max(rd[i - 1][j], rd[i][j] + ipt[i - 1][j]);
}
int ans = 0;
FE(i, 1, n) FE(j, 1, m)
{
if (i - 1 >= 1 && j - 1 >= 1 && i + 1 <= n && j + 1 <= m)
{
ans = max(ans, lu[i - 1][j] + ld[i][j - 1] + rd[i + 1][j] + ru[i][j + 1]);
}
if (j - 1 >= 1 && i + 1 <= n && j + 1 <= m && i - 1 >= 1)
{
ans = max(ans, lu[i][j - 1] + ld[i + 1][j] + rd[i][j + 1] + ru[i - 1][j]);
}
}
WI(ans);
}
return 0;
}

Codeforces Round #245 (Div. 1)——Working out的更多相关文章

  1. Codeforces Round #245 (Div. 1) 429D - Tricky Function 最近点对

    D. Tricky Function Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 codeforces.com/problemset/problem/42 ...

  2. Codeforces Round #245 (Div. 1) B. Working out (简单DP)

    题目链接:http://codeforces.com/problemset/problem/429/B 给你一个矩阵,一个人从(1, 1) ->(n, m),只能向下或者向右: 一个人从(n, ...

  3. Codeforces Round #245 (Div. 1) B. Working out (dp)

    题目:http://codeforces.com/problemset/problem/429/B 第一个人初始位置在(1,1),他必须走到(n,m)只能往下或者往右 第二个人初始位置在(n,1),他 ...

  4. Codeforces Round #245 (Div. 1) B. Working out dp

    题目链接: http://codeforces.com/contest/429/problem/B B. Working out time limit per test2 secondsmemory ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. Codeforces 429 B. Working out-dp( Codeforces Round #245 (Div. 1))

    B. Working out time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  9. Codeforces Round #245 (Div. 2) B - Balls Game

    暴利搜索即可 #include <iostream> #include <vector> #include <iostream> using namespace s ...

  10. Codeforces Round #245 (Div. 2) A - Points and Segments (easy)

    水到家了 #include <iostream> #include <vector> #include <algorithm> using namespace st ...

随机推荐

  1. ALSA音频工具amixer,aplay,arecord

    ALSA音频工具编译安装 ========================================================================1.官网http://www. ...

  2. Can you solve this equation?(二分)

    Can you solve this equation? Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Ja ...

  3. sqlplus常用操作命令2

    常用编辑命令:A[ppend] text 将text附加到当前行之后C[hange] /old /new 将当前行中的old替换为newCLear] buff[er] 清除缓冲区中的所有行DEL 删除 ...

  4. FCKeditor

    FCKeditor是一个专门使用在网页上属于开放源代码的所见即所得文字编辑器.它志于轻量化,不需要太复杂的安装步骤即可使用.     它可和PHP.JavaScript.ASP.ASP.NET.Col ...

  5. 实现接口IDisposable的示例

    想使用using(...), 如: using (Getter process = new Getter()) { //... } 就必须给类实现接口IDisposable public sealed ...

  6. 【转】通过Navicat for MySQL远程连接的时候报错mysql 1130的解决方法

    错误代码是1130,ERROR 1130: Host xxx.xxx.xxx.xxx is not allowed to connect to this MySQL server 是无法给远程连接的用 ...

  7. 详解AJAX核心 —— XMLHttpRequest 对象 (下)

    继续上一篇的内容上一篇关于XMLHttpRequest 对象发送对服务器的请求只说到了用Get方式,没有说Post方式的.那是因为要说Post方式就需要先说另外一个东西,那就是DOM(Document ...

  8. 使用Toad导入导出dmp数据

    进入Toad,选择Database->Import->Import Utility Wizard(导入则选择:Export->Export Utility Wizard与导入类似故不 ...

  9. APP设计规范大全

    大图可保存到本地

  10. Sql Server 2012启动存储过程

    可以通过如下步骤创建 1.打开show advanced options reconfigure 2.打开scan for startup procs,使得sql server在启动时扫描需要运行的p ...