WOJ1026-Game On Checkerboard
来源:互联网 发布:淘宝新店铺如何运营 编辑:程序博客网 时间:2024/06/06 16:49
Suppose that you are given an <img src="../upload/image/1026/g1.gif" /> checkerboard and a checker. Let?s have a game on the checkerboard right now. Here, you should
move the checker from the first row of the board to the last row of the board according to the following rule. At each step you may move the
checker to one of three squares:
1. the square immediately below.
2. the square that is one below and one to the left(but only if the checker is not already in the leftmost column).
3. the square that is one below and one to the right(but only if the checker is not already in the rightmost column).
Consider each square of the checkerboard is placed p(i, j) dollars, where i is the row number and j is the column number of the square.
You can move the checker from any square of the first row to any square of the last row, and pick up the dollars placed in the square you have
passed. What is the maximum number of dollars you can gather along the way?
输入格式
Standard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <= 50) which is the number of
test cases.
For each test case, the first line contains an integer N (1 <= N <= 1000), which denotes the checkerboard dimension. The following N lines contain N non-negative integers each, separated by a single blank space. The j-th element of the i-th row denotes the number of dollars
placed in the square of i-th row, j-th column. The first row is Row 1 and the last row is Row n.
输出格式
Results should be directed to standard output. Start each case with "Case #:" on a single line, where # is the case number starting from
- Two consecutive cases should be separated by a single blank line. No blank line should be produced after the last test case.
For each test case, output a single line containing an integer which is the maximum number of dollars you can gather along the way.
样例输入
131 3 57 0 84 0 0
样例输出
Case 1:14
#include<iostream>#include<cstdio>#include<cstring>using namespace std;int board[1010][1010],dp[1010][1010];int max3(int a,int b,int c){int max=a>b?a:b;max=max>c?max:c;return max;}int main(){int t,ti,n,i,j,ans=0;cin>>t;for(ti=1;ti<=t;ti++){cin>>n;memset(dp,0,sizeof(dp));for(i=1;i<=n;i++)for(j=1;j<=n;j++)cin>>board[i][j];for(j=1;j<=n;j++)dp[1][j]=board[1][j];for(i=2;i<=n;i++)for(j=1;j<=n;j++)dp[i][j]=max3(dp[i-1][j-1],dp[i-1][j],dp[i-1][j+1])+board[i][j];for(j=1;j<=n;j++)if(ans<dp[n][j])ans=dp[n][j]; if(ti!=1)puts("");printf("Case %d:\n",ti);cout<<ans<<endl;}return 0;}
- WOJ1026-Game On Checkerboard
- checkerboard
- game on demand
- <cf>Game on Paper
- CodeForces -Game on Paper
- [agc017d]Game on Tree
- Incomplete checkerboard covering
- matlab画checkerboard
- 棋盘(Checkerboard)算法
- Matching Game based on JS
- Android Game Development - Moving Images on Screen
- Bouncing Ball Game Code on Cortex-M4
- CodeForces 280C Game on Tree 概率
- HackerRank - number-game-on-a-tree
- [博弈] Codeforces Gym101190 NEERC2016G. Game on Graph
- codeforces 280C Game on Tree
- 简单的光照checkerboard球体shader实现
- Matlab之checkerboard-创建棋盘图像
- Springboot框架配置远程Tomcat服务器以及本地Tomcat服务器进行远程debug调试
- poj 1603 Risk(floyd)
- css中position相对定位和绝对定位(relative,absolute)详解
- 使用apidocJs快速生成在线文档
- PHP中preg_match正则表达式的使用
- WOJ1026-Game On Checkerboard
- 把easy-ui 单元格datagrid传数据到后台
- mysql 大对象类型对应大小 Blob Text
- 二级java程序设计--图形用户界面(1)
- HttpUtil
- 视频网站选择搭建主机的方法
- 加多芬为您提供完善的系统部署
- error-page配置错误页面
- windows版redis安装使用