Hackatari Codeathon C. Arcade (DP) (scrolling array)

Source: Internet
Author: User

C. ArcadeTime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Abdullah and Haritha were building a 3D printed arcade machine. Abdullah had worked on the hardware and while Haritha had been working on the game that'll be running on the arcade machine .

The game is represented as a 2D grid of R rows and C columns. The goal of the game is to build the maximum possible number of Hackatari logos. Hackatari ' s logo consists of 5 symbols, they is: {x,? o,?? >?,?? -?,?| }. When the game starts, the player would have a infinite number of the first and symbols {x,? and O}.

Each cell of the grid contains one of the three-to-last symbols of the logo, specifically, {?>?,?? -?,? or | }.

The player is placed at the Top-left cell, and was only allowed-to-move to the cell below him, or-to-the-to-he right. The player is not a allowed to go outside the grid. To collect a-a symbol from a cell, the player needs-to-move to that cell. The goal of the game is to build the maximum number of Hackatari logos using the collected symbols.

Abdullah was testing Haritha's game, recently, and he got a score of 103%, which means that the maximum score that Har Itha expected, was less than the maximum score that the player can actually achieve.

Can Haritha fix his game by writing a program that finds the maximum number of logos so can actually be built??

Input

The first line of input contains the integers, R and C (1?≤? R,? C. ≤?100), the number of rows and the number of columns in the grid, respectively.

Each of the following R lines contains C characters, each character belongs to the set: { ?>?,?? -?,?| }.

Output

On a, print the maximum number of Hackatari logos.

Examplesinput
3 4
>|>-
-|->
->-|
Output
2
Input
4 2
>-
>-
>-
||
Output
1
"Analysis" to give you a picture, start in the upper left corner, need to go to the lower right corner, each time only down or to the right, asked the number of the three symbols of the minimum amount of what.
Dp[i][j][x][y] Indicates whether the position of the i,j is >,| x, Y, respectively. This array is 100*100*200*200, found burst memory ...
Then there is the scroll array this thing, because when the first line to sweep to the last row is useful, then you can delete the previous, so you can open 3*100*200*200.
#include <iostream>#include<cstring>#include<cstdio>#include<algorithm>#include<cmath>#include<string>#include<map>#include<stack>#include<queue>#include<vector>#defineINF 0x3f3f3f3f#defineMet (b) memset (a,b,sizeof a)#definePB Push_back#defineMP Make_pairtypedefLong Longll;using namespacestd;Const intN = 1e2+Ten;Const intM = 1e6+Ten;intn,m,k,tot=0, q;BOOLdp[3][n][2*n][2*N];CharStr[n][n];intMain () {scanf ("%d%d",&n,&m);  for(intI=1; i<=n;i++) {scanf ("%s", str[i]+1); } dp[0][1][0][0]=true;  for(intI=1; i<=n;i++) {Met (dp[(i+1)%3],0);  for(intj=1; j<=m;j++){             for(intx=0; x<=i+j-1; x + +){                 for(inty=0; x+y<=i+j-1; y++){                    if(Dp[(i+2)%3][j][x][y]| | dp[i%3][j-1][x][y]) {if(str[i][j]=='>') dp[i%3][j][x+1][y]=true; if(str[i][j]=='|') dp[i%3][j][x][y+1]=true; if(str[i][j]=='-') dp[i%3][j][x][y]=true; }                }            }        }    }    intans=0;  for(intI=0; i<m+n;i++){         for(intj=0; i+j<m+n;j++){            if(dp[n%3][m][i][j]) {intRet=min (I,min (j,m+n-1-i-j)); Ans=Max (Ret,ans); }}} printf ("%d\n", ans); return 0;}

Hackatari Codeathon C. Arcade (DP) (scrolling array)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.