C. Arcade
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Abdullah and Haritha were building a 3D printed arcade machine. Abdullah had worked on the hardware, while Haritha had been working on the game that will 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 are: {x, o,  > ,  - , | }. When the game starts, the player will have an infinite number of the first two 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 is only allowed to move to the cell below him, or to the one to his right. The player is not allowed to go outside the grid. To collect 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 Haritha expected, was less than the maximum score that the player can actually achieve.

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

Input

The first line of input contains two 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 single line, print the maximum number of Hackatari logos.

Examples
Input
3 4
>|>-
-|->
->-|
Output
2
Input
4 2
>-
>-
>-
||
Output
1
【分析】给你一个图,开始在左上角,需要走向右下角 ,每次只能向下或者向右,问经过的这三种符号数量最小的是多少 。
dp[i][j][x][y]表示走到i,j这个位置经过>,|分别为x,y次这种情况是否存在。这个数组是100*100*200*200的,发现爆内存。。。
然后就有滚动数组这个东西了,因为当扫到第i行时,只有上一行有用,那么就可以将之前的删了,所以就可以开3*100*200*200的。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#define inf 0x3f3f3f3f
#define met(a,b) memset(a,b,sizeof a)
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
const int N = 1e2+;
const int M = 1e6+;
int n,m,k,tot=,q;
bool dp[][N][*N][*N];
char str[N][N];
int main(){
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++){
scanf("%s",str[i]+);
}
dp[][][][]=true;
for(int i=;i<=n;i++){
met(dp[(i+)%],);
for(int j=;j<=m;j++){
for(int x=;x<=i+j-;x++){
for(int y=;x+y<=i+j-;y++){
if(dp[(i+)%][j][x][y]||dp[i%][j-][x][y]){
if(str[i][j]=='>')dp[i%][j][x+][y]=true;
if(str[i][j]=='|')dp[i%][j][x][y+]=true;
if(str[i][j]=='-')dp[i%][j][x][y]=true;
}
}
}
}
}
int ans=;
for(int i=;i<m+n;i++){
for(int j=;i+j<m+n;j++){
if(dp[n%][m][i][j]){
int ret=min(i,min(j,m+n--i-j));
ans=max(ret,ans);
}
}
}
printf("%d\n",ans);
return ;
}

最新文章

  1. Java中的BoneCP数据库连接池用法
  2. Java tomcat启动失败(Servlet3.0 Web Project):A child container failed during start
  3. Mergely – 免费的在线文档对比和合并工具
  4. SequoiaDB 系列之三 :SequoiaDB的高级功能
  5. 【转】简单的 Laravel 5 REST API
  6. CentOS下更新python版本
  7. UIButton setImage setBackgoundImage
  8. 日历组件的使用,bootstrap-datetimepicker
  9. [原创] JavaScript实现简单的颜色类标签云
  10. 【2017-05-02】winform弹出警告框是否进行增删改操作、记事本制作、对话框控件和输出输入流
  11. DelayQueue使用
  12. Python应用场景
  13. SpringMVC源码情操陶冶-DispatcherServlet
  14. 4c语言的第0次作业
  15. 借助HTML中的特殊符号在markdown中打印出来
  16. 【Spring】DispatcherServlet的启动和初始化
  17. CSAPP:信息的表和处理2
  18. JHipster技术简介
  19. unicode 和 utf-8字符编码的区别
  20. cglib动态代理导致注解丢失问题及如何修改注解允许被继承

热门文章

  1. 使用MyBatis查询 返回类型为int,但是当查询结果为空NULL,报异常的解决方法
  2. java servlet jsp 导入boostrap css js
  3. bootstrap基本用法
  4. TensorFlow两种方式计算Cross Entropy
  5. wait与waitpid
  6. Python2.7.3 Tkinter Entry(文本框) 说明
  7. (二十)ubuntu的recovery mode解决用户一些实际问题
  8. 【bzoj3223】文艺平衡树
  9. VPS性能测试(1):CPU物理个数、内核、超线程、多核心
  10. make :err Makefile.ssl is older than Makefile.org. Reconfigure the source tree (via &#39;./config&#39; or &#39;perl Configure&#39;), please.