南邮 OJ 1998 GRID
2015-08-08 09:55
405 查看
GRID
时间限制(普通/Java) : 2500 MS/ 7500 MS 运行内存限制 : 65536 KByte总提交 : 105 测试通过 : 28
比赛描述
I think most ACMers are familiar with grid map.
In a grid map. Each grid has its own value vij.
At the beginning you are on (0,0) and you have to go to (M,N)
You have two ways to move (0,1) and (1,0)
(0,1) means when you stand on(x,y) you move to (x,y+1)
(1,0) means when you stand on(x,y) you move to (x+1,y)
Now you have to find a way from (0,0) to (M,N) to make the combined value of all the grid you have passed is the largest.
Output the maximum combined value.
![](http://acm.njupt.edu.cn/acmhome/judge/images/111.png)
输入
In the first line there is an integer T. means there are T cases.
In the first line of each case there are 2 integers M,N<1000.
On the following M line each line has N integers;
The yth number on the ith line is vij <5000, which represents the value of grid (i,j).
输出
For each case you only to print an integer in a single line. The integer is the maximum combined value of the grids you
have passed.
样例输入
1
1 1
1
样例输出
1
提示
null
题目来源
3E
/* Wrong Answer at Test 1 #include<iostream> using namespace std; #define MAX_N 1001 int a[MAX_N][MAX_N]; int main(){ int t,n,m,i,j,sum; scanf("%d",&t); while(t--){ scanf("%d%d",&n,&m); for(i=1;i<=n;i++){ for(j=1;j<=m;j++){ scanf("%d",&a[i][j]); } } for(sum=1;sum<=n+m;sum++){ for(i=max(1,sum-m);i<=n && sum-i>=1;i++){ j = sum-i; a[i][j] += max(a[i-1][j],a[i][j-1]); } } printf("%d\n",a [m]); } } */ /* AC 828MS #include<iostream> using namespace std; #define MAX_N 1001 int a[MAX_N][MAX_N]; int main(){ int t,n,m,i,j,sum; scanf("%d",&t); while(t--){ scanf("%d%d",&n,&m); for(i=1;i<=n;i++){ for(j=1;j<=m;j++){ scanf("%d",&a[i][j]); } } for(i=2;i<=n;i++){ a[i][1] += a[i-1][1]; } for(j=2;j<=n;j++){ a[1][j] += a[1][j-1]; } for(sum=2;sum<=n+m;sum++){ for(i=max(2,sum-m);i<=n && sum-i>=2;i++){ j = sum-i; a[i][j] += max(a[i-1][j],a[i][j-1]); } } printf("%d\n",a [m]); } } */ // 234MS #include<iostream> using namespace std; #define MAX_N 1001 int a[MAX_N][MAX_N]; int getnum(){ int t,r; bool flag=0; while((t=getchar())<'0' || t>'9'){ if(t=='-'){ flag = 1; } } r = t-'0'; while((t=getchar())>='0' && t<='9'){ r = r*10 + t-'0'; } if(flag){ r = -r; } return r; } int main(){ int t,n,m,i,j,sum; // scanf("%d",&t); t = getnum(); while(t--){ // scanf("%d%d",&n,&m); n = getnum(); m = getnum(); for(i=1;i<=n;i++){ for(j=1;j<=m;j++){ // scanf("%d",&a[i][j]); a[i][j] = getnum(); } } for(i=2;i<=n;i++){ a[i][1] += a[i-1][1]; } for(j=2;j<=n;j++){ a[1][j] += a[1][j-1]; } for(sum=2;sum<=n+m;sum++){ for(i=max(2,sum-m);i<=n && sum-i>=2;i++){ j = sum-i; a[i][j] += max(a[i-1][j],a[i][j-1]); } } printf("%d\n",a [m]); } }
相关文章推荐
- 前端之路
- WPF 自定义Metro Style窗体
- Python实现多线程抓取妹子图
- 常用正则表达式
- HDU 1565 方格取数(1)(最小割-Dinic)
- 南邮 OJ 1997 二叉树
- 开发android,我们需要哪些技能基础
- 周末你好
- 用LUA写一个日历
- HDU 4734 F(x)
- Windows 7/Vista下安装Oracle Developer Suit遇到的几个问题
- elasticsearch marvel插件安装失败的解决方法
- 南邮 OJ 1996 ELEVATOR
- javascript 调用其他页面的js函数或变量的脚本
- 设计模式---
- 架构师速成8.3-架构师必须要了解的规则(转)
- 关于DDOS攻击
- vc 输出到调试器
- 常用前端开发工具合集
- FZUOJ2196 Escape(bfs)