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. Canvas 基本绘图方法总结

    一.基本内容  1.简单来说,HTML5提供的新元素<canvas>  2.Canvas在HTML页面提供画布的功能,在画布中绘制各种图形  3.Canvas绘制的图形与HTML页面无关, ...

  2. 【BZOJ】1419 Red is good

    [算法]期望DP [题解]其实把状态表示出来就是很简单的期望DP. f[i][j]表示i张红牌,j张黑牌的期望. i=0时,f[0][j]=0. j=0时,f[i][0]=i. f[i][j]=max ...

  3. 结合promise对原生fetch的两个then用法理解

    前言:该问题是由于看到fetch的then方法的使用,产生的疑问,在深入了解并记录对promise的个人理解 首先看一下fetch请求使用案例: 案例效果:点击页面按钮,请求当前目录下的arr.txt ...

  4. C# 读写XML文件示例

    using System; using System.Collections.Generic; using System.Text; using System.Configuration; using ...

  5. 【bzoj3545】peaks

    离线一下,动态开点+线段树合并,然后权值线段树上询问kth即可. #include<bits/stdc++.h> ; *; using namespace std; ; inline in ...

  6. 【NOIP2016】组合数问题

    写着玩玩…… 反正超级sb题. #include<bits/stdc++.h> typedef long long ll; using namespace std; ll c[][],h[ ...

  7. 16:django 有条件的视图处理(Last-Modified和ETag)&&加密签名

    有条件的视图处理 上一节我们介绍了缓存来减轻服务器的负担,这里的有条件的视图处理也从一定程度上减轻了服务器的负担,在正式介绍之前,先来看两个概念:Last-Modified和ETag Last-Mod ...

  8. linux命令(47):rmdir命令

    1.命令格式: rmdir [选项]... 目录... 2.命令功能: 该命令从一个目录中删除一个或多个子目录项,删除某目录时也必须具有对父目录的写权限. 3.命令参数: - p 递归删除目录dirn ...

  9. 《逐梦旅程 WINDOWS游戏编程之从零开始》笔记8——载入三维模型&Alpha混合技术&深度测试与Z缓存

    第17章 三维游戏模型的载入 主要是如何从3ds max中导出.X文件,以及如何从X文件加载三维模型到DirextX游戏程序里.因为复杂的3D物体,要用代码去实现,那太反人类了,所以我们需要一些建模软 ...

  10. Jump Game I&&II——入门级贪心算法

    Jump Game I Given an array of non-negative integers, you are initially positioned at the first index ...