题目链接

  • 题意:

    一个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. 在php添加mongo过程中出现的mongo.so: > undefined symbol: php_json_encode in Unknown on line 0. After installation mongo driver for php 的错误

    3 down vote my system is centos 6.3. I got the problem solved. vim /etc/php.ini then add extension=j ...

  2. 【C++第三课】---新的关键字

    一.动态分配内存的时的关键字 注意在C++中和C不一样的是,在C中使用的malloc来动态分配内存,而这个malloc只是标准C库的调用,所以这个不属于标准C的范畴,而在C++ 中却有真正的关键字来分 ...

  3. HTML中IE条件注释判断语句(<!--[if XX IE X]><![endif]-->)

    <!--[if XX IE X]><![endif]-->是IE专门提供的一种语法,其他浏览器会将其作为注释而忽略这些语句.   作用: 根据不同的IE版本加载对应的CSS或者 ...

  4. Arrays.copyof

    public static int[] copyOf(int[] original, int newLength) { int[] copy = new int[newLength]; System. ...

  5. iOS 在特定页面 界面旋转

    1.在AppDelegate.h 里添加标记 2.在AppDelegate.m 里添加这个方法 3.使用 [(AppDelegate*)[UIApplication sharedApplication ...

  6. HDU 1070 - Milk

    给每种牛奶价格和量 要求买最便宜的牛奶 #include <iostream> using namespace std; int t,n; ][]; ],v[]; int main() { ...

  7. X - A == B ?(第二季水)

    Description Give you two numbers A and B, if A is equal to B, you should print "YES", or p ...

  8. TCP/IP详解之:SNMP

    基于TCP/IP的网络管理包含3个组成部分: 一个管理信息库MIB:MIB包含所有代理进程的所有可被查询和修改的参数 关于MIB的一套公用的结构和表示符号,即SMI(管理信息结构) 管理进程和代理进程 ...

  9. redis 未授权漏洞利用直接登录服务器

    在没有查到杀手之前我是先把带宽&端口用iptables 做了限制这样能保证我能远程操作服务器才能查找原因 2 在各种netstat –ntlp  的查看下没有任何异常 在top 下查到了有异常 ...

  10. C#控制台程序本地化应用(Localization)

    本地化在百度百科上的解释如下: “软件本地化是指将某一产品的用户界面(UI)和辅助材料(文档资料和在线帮助菜单)从其原产国语言向另一种语言转化,使之适应某一外国语言和文化的过程.” 其原理主要是把相同 ...