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 ;
}

2017 Hackatari Codeathon C. Arcade(DP)(滚动数组)的更多相关文章

  1. HDU 1024 Max Sum Plus Plus --- dp+滚动数组

    HDU 1024 题目大意:给定m和n以及n个数,求n个数的m个连续子系列的最大值,要求子序列不想交. 解题思路:<1>动态规划,定义状态dp[i][j]表示序列前j个数的i段子序列的值, ...

  2. POJ 3666 Making the Grade (DP滚动数组)

    题意:农夫约翰想修一条尽量平缓的路,路的每一段海拔是A[i],修理后是B[i],花费|A[i] – B[i]|,求最小花费.(数据有问题,代码只是单调递增的情况) #include <stdio ...

  3. HDU 5119 Happy Matt Friends (背包DP + 滚动数组)

    题目链接:HDU 5119 Problem Description Matt has N friends. They are playing a game together. Each of Matt ...

  4. USACO 2009 Open Grazing2 /// DP+滚动数组oj26223

    题目大意: 输入n,s:n头牛 s个栅栏 输入n头牛的初始位置 改变他们的位置,满足 1.第一头与最后一头的距离尽量大 2.相邻两头牛之间的距离尽量满足 d=(s-1)/(n-1),偏差不超过1 3. ...

  5. BZOJ-1925 地精部落 烧脑DP+滚动数组

    1925: [Sdoi2010]地精部落 Time Limit: 10 Sec Memory Limit: 64 MB Submit: 1053 Solved: 633 [Submit][Status ...

  6. Codeforces 712 D. Memory and Scores (DP+滚动数组+前缀和优化)

    题目链接:http://codeforces.com/contest/712/problem/D A初始有一个分数a,B初始有一个分数b,有t轮比赛,每次比赛都可以取[-k, k]之间的数,问你最后A ...

  7. hdu 1513 && 1159 poj Palindrome (dp, 滚动数组, LCS)

    题目 以前做过的一道题, 今天又加了一种方法 整理了一下..... 题意:给出一个字符串,问要将这个字符串变成回文串要添加最少几个字符. 方法一: 将该字符串与其反转求一次LCS,然后所求就是n减去 ...

  8. 【BZOJ】1925: [Sdoi2010]地精部落 DP+滚动数组

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1925 题意:输入一个数N(1 <= N <= 4200),问将这些数排列成折线 ...

  9. tyvj P1519 博彩游戏(AC自动机+DP滚动数组)

    P1519 博彩游戏 背景 Bob最近迷上了一个博彩游戏…… 描述 这个游戏的规则是这样的:每花一块钱可以得到一个随机数R,花上N块钱就可以得到一个随机序列:有M个序列,如果某个序列是产生的随机序列的 ...

随机推荐

  1. MyBatis框架的使用及源码分析(三) 配置篇 Configuration

    从上文<MyBatis框架中Mapper映射配置的使用及原理解析(二) 配置篇 SqlSessionFactoryBuilder,XMLConfigBuilder> 我们知道XMLConf ...

  2. 全面了解Nginx主要应用场景(数漫江湖)

    前言 本文只针对Nginx在不加载第三方模块的情况能处理哪些事情,由于第三方模块太多所以也介绍不完,当然本文本身也可能介绍的不完整,毕竟只是我个人使用过和了解到过得.所以还请见谅,同时欢迎留言交流 N ...

  3. bzoj 1197 DP

    我们可以将这个问题转化为在n维空间中一共放m个n维球,求这m个球最多将这个空间分为不同的几个部分. 那么我们设w[i][j]代表i为空间放j个球分为的部分,那么w[i][j]=w[i][j-1]+w[ ...

  4. vue实现微信对话

    因为项目中需要实现仿微信对话功能,于是抽空实现了下,主要是h5的canvas的把图片和文字绘制到画布上 原文来自我的个人博客:http://lvhww.com/index.php/archives/6 ...

  5. CursorFileManager对cursor文件的读写

    public class CursorFileManager implements CursorManager{public void write(String key, LongCursor cur ...

  6. Yii 1.1.17 三、数据库连接、定义模型、数据查询、验证登录、SESSION使用与URL生成

    一.数据库连接 1.配置连接参数 在database.php里面开启: 'db' => array( 'connectionString' => 'mysql:host=127.0.0.1 ...

  7. 包装类、基本数据类型及String类之间的相互转换

    包装类:8种基本数据类型对应一个类,此类即为包装类 一.基本数据类型 包装类 及String之间的转换 1.基本数据类型转化为包装类:调用包装类的构造器      int i=10;     Inte ...

  8. 实现atoi函数

    atoi函数最关键的地方是想好测试用例: 输入为空字符串,输出为0; 输入字符串大小超过INT_MAX输出INT_MAX; 输入字符串大小小于INT_MIN输出INT_MIN; 输入字符串中含有不规则 ...

  9. Codeforces 877C Slava and tanks(思维)

    题目链接:http://codeforces.com/problemset 题目大意:有n个格子,某些格子里可能有一个或多个坦克,但不知道具体位置,每个坦克被轰炸一次就会移动到相邻的格子里(第1个格子 ...

  10. Spring + MyBatis 多数据源实现

    近期,在项目中需要做分库,但是因为某些原因,没有采用开源的分库插件,而是采用了同事之前弄得多数据源形式实现的分库.对于多数据源,本人在实际项目也中遇到的不多,之前的项目大多是服务化,以RPC的形式获得 ...