CodeForces 214E - Relay Race(二取方格数)
来源:互联网 发布:个人短信群发平台知乎 编辑:程序博客网 时间:2024/06/05 16:31
Furik and Rubik take part in a relay race. The race will be set up on a large square with the side ofn meters. The given square is split into n × n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell with coordinates (n, n). Right after the start Furik runs towards Rubik, besides, if Furik stands at a cell with coordinates(i, j), then he can move to cell (i + 1, j) or (i, j + 1). After Furik reaches Rubik, Rubik starts running from cell with coordinates(n, n) to cell with coordinates (1, 1). If Rubik stands in cell (i, j), then he can move to cell(i - 1, j) or (i, j - 1). Neither Furik, nor Rubik are allowed to go beyond the boundaries of the field; if a player goes beyond the boundaries, he will be disqualified.
To win the race, Furik and Rubik must earn as many points as possible. The number of points is the sum of numbers from the cells Furik and Rubik visited.Each cell counts only once in the sum.
Print the maximum number of points Furik and Rubik can earn on the relay race.
The first line contains a single integer (1 ≤ n ≤ 300). The nextn lines contain n integers each: thej-th number on the i-th line ai, j( - 1000 ≤ ai, j ≤ 1000) is the number written in the cell with coordinates(i, j).
On a single line print a single number — the answer to the problem.
15
5
211 1416 12
53
325 16 2512 18 1911 13 8
136
Comments to the second sample: The profitable path for Furik is: (1, 1), (1, 2), (2, 2), and for Rubik:(2, 2), (2, 1), (1, 1).
Comments to the third sample: The optimal path for Furik is: (1, 1), (1, 2), (1, 3),(2, 3), (3, 3), and for Rubik:(3, 3), (3, 2), (2, 2), (2, 1), (1, 1). The figure to the sample:
==========================
#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int INF=0x3f3f3f3f;int f[605][301][301],n;int a[301][301];int main(){ memset(f,-INF,sizeof(f)); scanf("%d",&n); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) scanf("%d",&a[i][j]); f[1][1][1]=a[1][1]; for(int k=2;k<=n+n-1;k++)//第几个对角线 { for(int x1=1;x1<=n;x1++) { for(int x2=1;x2<=n;x2++) { int p=max(f[k-1][x1-1][x2-1],f[k-1][x1-1][x2]); p=max(f[k-1][x1][x2-1],p); p=max(f[k-1][x1][x2],p); if(x1!=x2) f[k][x1][x2]=p+a[x1][k+1-x1]+a[x2][k+1-x2]; else f[k][x1][x2]=p+a[x1][k+1-x1];//相等的时候说明两人在同一位置所以只加一遍 } } } printf("%d\n",f[n+n-1][n][n]); return 0;}
- CodeForces 214E - Relay Race(二取方格数)
- codeforces 214E-Relay Race
- Codeforces 214E. Relay Race dp
- Codeforces 214E Relay Race【Dp】
- Codeforces Round #131 (Div. 2) E. Relay Race
- CodeForces 213C Relay Race
- CodeForces 213C-Relay Race
- Codeforces 213C Relay Race
- codeforces 213C Relay Race(DP基础,棋盘路径)
- 二、Noip2000,方格取数题解(DP)
- codeforces 43E Race
- codeforces 213C Relay Race(dp)
- CodeForces 213C Relay Race(dp)
- hdu(1565)方格取数(1)
- noip2000 方格取数 (动态规划)
- 蓝桥杯 方格取数 (多线程DP)
- 方格取数(动规例题)
- 方格取数问题(最大流)
- MD5 校验两个文件是否一样
- 【Oracle优化笔记】访问索引的方法
- android 全屏,无标题栏
- imo电子白板共享时无法插入文档的解决办法
- UIActivityIndicatorView活动指示器
- CodeForces 214E - Relay Race(二取方格数)
- Unix chroot最佳实践
- HOG特征与opencv类实现
- loadrunner 关联方法 详细
- JSP中文乱码处理之Servlet接收参数中文乱码处理
- 面试时所遇问题总结
- 文档索引模型
- 黑马程序员---银行管理系统
- 产品经理