2017 Hackatari Codeathon C. Arcade(DP)(滚动数组)
1 second
256 megabytes
standard input
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??
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: { > , - , | }.
On a single line, print the maximum number of Hackatari logos.
3 4
>|>-
-|->
->-|
2
4 2
>-
>-
>-
||
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)(滚动数组)的更多相关文章
- HDU 1024 Max Sum Plus Plus --- dp+滚动数组
HDU 1024 题目大意:给定m和n以及n个数,求n个数的m个连续子系列的最大值,要求子序列不想交. 解题思路:<1>动态规划,定义状态dp[i][j]表示序列前j个数的i段子序列的值, ...
- POJ 3666 Making the Grade (DP滚动数组)
题意:农夫约翰想修一条尽量平缓的路,路的每一段海拔是A[i],修理后是B[i],花费|A[i] – B[i]|,求最小花费.(数据有问题,代码只是单调递增的情况) #include <stdio ...
- HDU 5119 Happy Matt Friends (背包DP + 滚动数组)
题目链接:HDU 5119 Problem Description Matt has N friends. They are playing a game together. Each of Matt ...
- USACO 2009 Open Grazing2 /// DP+滚动数组oj26223
题目大意: 输入n,s:n头牛 s个栅栏 输入n头牛的初始位置 改变他们的位置,满足 1.第一头与最后一头的距离尽量大 2.相邻两头牛之间的距离尽量满足 d=(s-1)/(n-1),偏差不超过1 3. ...
- BZOJ-1925 地精部落 烧脑DP+滚动数组
1925: [Sdoi2010]地精部落 Time Limit: 10 Sec Memory Limit: 64 MB Submit: 1053 Solved: 633 [Submit][Status ...
- Codeforces 712 D. Memory and Scores (DP+滚动数组+前缀和优化)
题目链接:http://codeforces.com/contest/712/problem/D A初始有一个分数a,B初始有一个分数b,有t轮比赛,每次比赛都可以取[-k, k]之间的数,问你最后A ...
- hdu 1513 && 1159 poj Palindrome (dp, 滚动数组, LCS)
题目 以前做过的一道题, 今天又加了一种方法 整理了一下..... 题意:给出一个字符串,问要将这个字符串变成回文串要添加最少几个字符. 方法一: 将该字符串与其反转求一次LCS,然后所求就是n减去 ...
- 【BZOJ】1925: [Sdoi2010]地精部落 DP+滚动数组
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1925 题意:输入一个数N(1 <= N <= 4200),问将这些数排列成折线 ...
- tyvj P1519 博彩游戏(AC自动机+DP滚动数组)
P1519 博彩游戏 背景 Bob最近迷上了一个博彩游戏…… 描述 这个游戏的规则是这样的:每花一块钱可以得到一个随机数R,花上N块钱就可以得到一个随机序列:有M个序列,如果某个序列是产生的随机序列的 ...
随机推荐
- [洛谷P1941] 飞扬的小鸟
洛谷题目链接:飞扬的小鸟 题目描述 Flappy Bird是一款风靡一时的休闲手机游戏.玩家需要不断控制点击手机屏幕的频率来调节小鸟的飞行高度,让小鸟顺利通过画面右方的管道缝隙.如果小鸟一不小心撞到了 ...
- HDU 2059 龟兔赛跑 (dp)
题目链接 Problem Description 据说在很久很久以前,可怜的兔子经历了人生中最大的打击--赛跑输给乌龟后,心中郁闷,发誓要报仇雪恨,于是躲进了杭州下沙某农业园卧薪尝胆潜心修炼,终于练成 ...
- Python ctypes的byref和pointer有啥区别
byref(n)返回的相当于C的指针右值&n,本身没有被分配空间: >>> from ctypes import *>>> n = c_int(0)> ...
- 概率DP入门学习QAQ
emmmm博客很多都烂尾了...但是没空写..先写一下正在学的东西好了 概率DP这东西每次考到都不会..听题解也是一脸懵逼..所以决定学习一下这个东东..毕竟NOIP考过...比什么平衡树实在多了QA ...
- perl模拟登录(1)
use WWW::Mechanize; my $ua = WWW::Mechanize->new(); $ua->post('http://localhost/dvwa/DVWA-mast ...
- linux之cron定时任务介绍
前言 linux系统有一个专门用来管理定时任务的进程cron,一般是设置成开机自启动的,通过添加任务可以让服务器定时执行某些任务. cron介绍 linux系统有一个专门用来管理定时任务的进程cron ...
- 【Windows使用笔记】使Onedrive同步任意文件夹
因为度盘实在是有点垃圾,经常看的剧之类的或者其他软件资源啥的动不动就被封. 所以跑去某宝买了一个5T的企业子账号,安全性不清楚,重要的隐私数据反正都用移动硬盘备份了.主要就是存一些资源性的文件吧.而且 ...
- 【常见的SQL Server连接失败错误以及解决方法】
[常见的SQL Server连接失败错误以及解决方法] http://blog.csdn.net/feixianxxx/article/details/5523922 ADO连接SQL Server ...
- mac 使用清除废纸篓或彻底删除某文件 附加: smb afp ftp NAS 访问服务器相关
mac 使用清除废纸篓或彻底删除某文件 附加: smb afp ftp NAS 访问服务器相关 mac 下删除文件方法: 1.使用 cleanmymac 使用 cleamymac 的清理 和 逐个 ...
- JavaScript自定义事件,动态添加属性
根据事件的不同,可用的自定义方法也不同. document.createEvent('Event'); 实现主要有4个步骤: 1.创建事件. 2.初始化事件(三个参数:事件名,是否起泡,是否取消默认触 ...