HDU 2280 Tetris Comes Back
状态压缩,$dp$,预处理。
设$dp[i][j]$为前$i-1$行填满,第$i$行为状态$j$的最小需要$1$种类的数量。预处理好每种状态能推出哪些状态,并且记录下所需花费就可以了。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c = getchar();
x = ;
while(!isdigit(c)) c = getchar();
while(isdigit(c)) { x = x * + c - ''; c = getchar(); }
} struct X
{
int nx,cost;
}q[];
int n,c,cnt;
vector<int>v[];
char s[][];
int st[];
int dp[][]; int check(int s,int pos)
{
if(s&(<<pos)) return ;
return ;
} void dfs(int S,int no,int p,int nx,int co)
{
if(p==)
{
q[cnt].nx=nx; q[cnt].cost=co;
v[S].push_back(cnt); cnt++;
return ;
} if(check(no,p))
dfs(S,no,p+,nx,co); //
if(check(no,p)==)
dfs(S,no+(<<p),p+,nx,co+); //
if(p>&&check(no,p)==&&check(nx,p)==&&check(nx,p-)==)
dfs(S,no+(<<p),p+,nx+(<<p)+(<<(p-)),co);
//
if(p+<=&&check(no,p)==&&check(no,p+)==&&check(nx,p)==&&check(nx,p+)==)
dfs(S,no+(<<p)+(<<(p+)),p+,nx+(<<p)+(<<(p+)),co); //
if(p+<=&&check(no,p)==&&check(no,p+)==)
dfs(S,no+(<<p)+(<<(p+)),p+,nx,co); //
if(check(no,p)==&&check(nx,p)==)
dfs(S,no+(<<p),p+,nx+(<<p),co); //
if(p+<=&&check(no,p)==&&check(nx,p)==&&check(nx,p+)==)
dfs(S,no+(<<p),p+,nx+(<<p)+(<<(p+)),co); //
if(p+<=&&check(no,p)==&&check(no,p+)==&&check(nx,p+)==)
dfs(S,no+(<<p)+(<<(p+)),p+,nx+(<<(p+)),co); //
if(p+<=&&check(no,p)==&&check(no,p+)==&&check(nx,p)==)
dfs(S,no+(<<p)+(<<(p+)),p+,nx+(<<p),co);
} void init()
{
cnt=;
for(int i=;i<(<<);i++) dfs(i,i,,,);
} int main()
{
init(); while(~scanf("%d%d",&n,&c))
{
for(int i=;i<n;i++) scanf("%s",s[i]);
for(int i=;i<n;i++)
{
st[i]=;
for(int j=;j<;j++)
{
int x=s[i][j]-'';
st[i]=st[i]+x*(<<j);
}
} st[n]=; memset(dp,-,sizeof dp); dp[][st[]]=; for(int i=;i<n;i++)
{
for(int j=;j<;j++)
{
if(dp[i][j]==-) continue;
//printf("********\n");
for(int t=;t<v[j].size();t++)
{
int id=v[j][t];
if(c-dp[i][j]<q[id].cost) continue;
if(st[i+]&q[id].nx) continue;
if(dp[i+][(q[id].nx)|st[i+]]==-) dp[i+][(q[id].nx)|st[i+]]=dp[i][j]+q[id].cost;
else dp[i+][(q[id].nx)|st[i+]]=min(dp[i+][(q[id].nx)|st[i+]],dp[i][j]+q[id].cost);
}
}
} if(dp[n][]!=-&&dp[n][]<=c) printf("YES\n");
else printf("NO\n");
}
return ;
}
HDU 2280 Tetris Comes Back的更多相关文章
- hdu 5374 Tetris(模拟)
pid=5374">题目链接:hdu 5374 Tetris 模拟.每次进行操作时推断操作是否合法,合法才运行,否则跳过.每次一个token落地,推断一下是否有消除整行. #inclu ...
- HDU 5374 Tetris (2015年多校比赛第7场)
1.题目描写叙述:点击打开链接 2.解题思路:本题要求模拟俄罗斯方块游戏.然而比赛时候写了好久还是没过. 后来补题发现原来是第四步的逻辑实现写错了... 题目中要求假设一整行能够消除,那么仍然运行该步 ...
- HDU 2280 状压DP
用dfs找到状态的最优解 且那个正方形块可以由两个水平块组成,所以无需考虑 #include <cstdio> #include <cstring> #include < ...
- ACM: hdu 1811 Rank of Tetris - 拓扑排序-并查集-离线
hdu 1811 Rank of Tetris Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- hdu 1811 Rank of Tetris - 拓扑排序 - 并查集
自从Lele开发了Rating系统,他的Tetris事业更是如虎添翼,不久他遍把这个游戏推向了全球. 为了更好的符合那些爱好者的喜好,Lele又想了一个新点子:他将制作一个全球Tetris高手排行榜, ...
- HDU 1811 Rank of Tetris(并查集按秩合并+拓扑排序)
Rank of Tetris Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- HDU 1811:Rank of Tetris(并查集+拓扑排序)
http://acm.hdu.edu.cn/showproblem.php?pid=1811 Rank of Tetris Problem Description 自从Lele开发了Rating系 ...
- HDU 1811 Rank of Tetris(拓扑排序+并查集)
题目链接: 传送门 Rank of Tetris Time Limit: 1000MS Memory Limit: 32768 K Description 自从Lele开发了Rating系统, ...
- hdu 1811 Rank of Tetris (并查集+拓扑排序)
Rank of Tetris Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
随机推荐
- IE6中png背景图片透明的最好处理方法
在IE6浏览器下png(24位)的图片显示是不能透明的. 1.处理办法就是用DDPngMin.js <!--[if IE 6]> <script src="js/DDPng ...
- ns统计使用资源的SNMP OID
ns统计使用资源的SNMP OID > add snmp manager 192.168.195.1 > add snmp community public ALL > add sn ...
- 【NOIP模拟赛】beautiful 乱搞(平衡树)+ST
biubiu~~~ 我用平衡树处理的这道题,然而这种方法还是要看评测姬..... 正解是乱搞....就是枚举每一位数作为中位数,比他小的看做-1比他大的看做1,那么我们从一开始就有了一个绵延的山,我们 ...
- Leetcode 45. Jump Game II(贪心)
45. Jump Game II 题目链接:https://leetcode.com/problems/jump-game-ii/ Description: Given an array of non ...
- codeforces 1015A
A. Points in Segments time limit per test 1 second memory limit per test 256 megabytes input standar ...
- shell监控进程是否存在
1.直接给代码:我这个是两个程序.多半要写成函数 [root@java1 src]# cat checkprocess.sh #!/bin/bashcheckprocess(){ps -ef|grep ...
- Python代码规范
一:背景 用于规范化ocp python开发,对于使用python开发的程序使用统一的风格,便于代码的维护 二:python风格规范 分号:不要在行尾加分号,也不要用分号将两条命令放在同一行 括号:宁 ...
- PushState+Ajax 完美实现无刷新
转载自:http://lazynight.me/1897.html 折腾一下PJAX,利用HTML5的新API,实现历史记录的完美导入. 不知道你用没用过Github,里边的目录跳转就是用html5的 ...
- 编写一个 Chrome 浏览器扩展程序
浏览器扩展允许我们编写程序来实现对浏览器元素(书签.导航等)以及对网页元素的交互, 甚至从 web 服务器获取数据,以 Chrome 浏览器扩展为例,扩展文件包括: 一个manifest文件(主文件, ...
- leetcode-501. Find Mode in Binary Search Tree
Given a binary search tree (BST) with duplicates, find all the mode(s) (the most frequently occurred ...