题目链接

  • 题意:

    一个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. 【LeetCode练习题】Minimum Path Sum

    Minimum Path Sum Given a m x n grid filled with non-negative numbers, find a path from top left to b ...

  2. nginx编译配置

    1, 正向代理是一个位于内网客户端和外网原始服务器之间的服务器,为了从原始服务器取得内容,客户端向代理发送一个请求并指定目标,然后由代理服务器向 原始服务器转交请求并将获得的内容返回给客户端.正向代理 ...

  3. 《火球——UML大战需求分析》(第3章 分析业务模型-类图)——3.8 小结与练习

    摘要:类图(Class Diagram)可能是用得最多的一种UML图.类图的基本语法并不复杂,你可能最多学习两三天就可以掌握,然而要真正做到活用类图则可能需要几年的功力.类图是锻炼面向对象分析(OOA ...

  4. 二十七、Java图形化界面设计——容器(JFrame)

    摘自http://blog.csdn.net/liujun13579/article/details/7756729 二十七.Java图形化界面设计--容器(JFrame) 程序是为了方便用户使用的, ...

  5. .net网站开发(设计):1.什么是MVC模式

    好吧我知道,应该很少人一开始学网站开发就从MVC开始,但如果你已经理解了三层架构之类的,那直接尝试强大的微软MVC网站开发模式也是挺不错的. 但其实我们学校有个实验室,那些干进去的就算是大一的学生,也 ...

  6. 网络编程API-下 (I/O复用函数)

    IO复用是Linux中的IO模型之中的一个,IO复用就是进程预先告诉内核须要监视的IO条件,使得内核一旦发现进程指定的一个或多个IO条件就绪,就通过进程进程处理.从而不会在单个IO上堵塞了. Linu ...

  7. sharepreference实现记住password功能

        SharePreference是用于保存数据用的.主要调用Context.getSharePreferences(String name, int mode)方法来得到SharePrefere ...

  8. ISO9126 质量模型

    功能性 适合性:当软件在指定条件下使用,其满足明确和隐含要求功能的能力. 准确性:软件提供给用户功能的精确度是否符合目标. 互操作性:软件与其它系统进行交互的能力. 安全性:软件保护信息和数据的安全能 ...

  9. [KMP求最小循环节][HDU1358][Period]

    题意 求所有循环次数大于1的前缀 的最大循环次数和前缀位置 解法 直接用KMP求最小循环节 当满足i%(i-next[i])&&next[i]!=0 前缀循环次数大于1 最小循环节是i ...

  10. 【贪心+中位数】【新生赛3 1007题】 Problem G (K)

    Problem G Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Sub ...