HDU-4272 LianLianKan
http://acm.hdu.edu.cn/showproblem.php?pid=4272
据说是状态压缩,+dfs什么什么的,可我这样也过了,什么算法都是浮云 ,暴力才是王道。我也归类为状态压缩,可以用状态压缩来做。
LianLianKan
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2482 Accepted Submission(s): 773
Now we have a number stack, and we should link and pop the same element pairs from top to bottom. Each time, you can just link the top element with one same-value element. After pop them from stack, all left elements will fall down. Although the game seems to be interesting, it's really naive indeed.

To prove I am a wisdom among my friend, I add an additional rule to the game: for each top element, it can just link with the same-value element whose distance is less than 6 with it.
Before the game, I want to check whether I have a solution to pop all elements in the stack.
The first line is an integer N indicating the number of elements in the stack initially. (1 <= N <= 1000)
The next line contains N integer ai indicating the elements from bottom to top. (0 <= ai <= 2,000,000,000)
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main()
{
int n,j,i,k,a[],v[];
while(~scanf("%d",&n))
{
for(i=;i<=n;i++)
scanf("%d",&a[i]);
memset(v,,sizeof(v));
int cnt=;
int flag=;
while(cnt<n)
{
for(i=;i<=n;i++)
{
if(v[i]==)
continue;
k=;
for(j=i+;j<=n&&k<=;j++)
{
if(v[j]==)
continue;
if(a[i]==a[j])
{
v[i]=v[j]=;
break;
}
k++;
}
}
cnt++;
}
for(i=;i<=n;i++)
{
if(v[i]==)
{
printf("0\n");
break;
}
}
if(i>n)
printf("1\n"); }
return ;
}
HDU-4272 LianLianKan的更多相关文章
- hdu 4272 LianLianKan 状态压缩
LianLianKan Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- HDU 4272 LianLianKan (状压DP+DFS)题解
思路: 用状压DP+DFS遍历查找是否可行.假设一个数为x,那么他最远可以消去的点为x+9,因为x+1~x+4都能被他前面的点消去,所以我们将2进制的范围设为2^10,用0表示已经消去,1表示没有消去 ...
- HDU 4272 LianLianKan(状压DP)题解
题意:一个栈,每次可以选择和栈顶一样的数字,并且和栈顶距离小于6,然后同时消去他们,问能不能把所有的数消去 思路:一个数字最远能消去和他相距9的数,因为中间4个可以被他上面的消去.因为还要判断栈顶有没 ...
- LianLianKan - HDU 4272(状态压缩)
题目大意:有一列数据,可以从最上面的开始连接下面相同的元素,然后消除,不过距离不能超过6,询问最后能不能消除完整个数列. 分析:首先讨论一点最远能消除的地方,比如点的位置是x,如若想要消除x+1位置处 ...
- LianLianKan HDU - 4272 状压dp
题意:长度为n(n<=1000)的栈,栈顶元素可以与下面1~5个数中相同的元素消去,问最后能都完全消去. 题解: 比如这个序列12345678910112这个位置的最远可匹配位置能到11为什么呢 ...
- hdoj 4272 LianLianKan 数据太水
LianLianKan Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu 4272 2012长春赛区网络赛 dfs暴力 ***
总是T,以为要剪枝,后来发现加个map就行了 #include<cstdio> #include<iostream> #include<algorithm> #in ...
- 2012年长春网络赛(hdu命题)
为迎接9月14号hdu命题的长春网络赛 ACM弱校的弱菜,苦逼的在机房(感谢有你)呻吟几声: 1.对于本次网络赛,本校一共6名正式队员,训练靠的是完全的自主学习意识 2.对于网络赛的群殴模式,想竞争现 ...
- HDU 1695 GCD (欧拉函数+容斥原理)
GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
随机推荐
- Eclipse - 安装 run-jetty-run 插件及使用 jrebel 热部署
安装 run-jetty-run 插件 1. 下载 run-jetty-run 2. 解压至 Eclipse/MyEclipse 安装目录下的 plugin 3. 右键 web 项工程,选择 Run ...
- Java静态变量,常量,成员变量,局部变量
类变量(也叫静态变量)是类中独立于方法之外的变量,用static 修饰.(static表示“全局的”.“静态的”,用来修饰成员变量和成员方法,或静态代码块(静态代码块独立于类成员,jvm加载类时会执行 ...
- SSO单点登录之数据同步
完成单点登录,我们便可以通过只登录一个账号,来访问不同系统,然而会遇到以下问题. 1. 通过A站登录的用户访问B站,在B站并没有真实用户,此时如果在B站新建用户,则可能造成用户信息不全,或者数据冲突等 ...
- [Mime] MimeEntity--MimeEntity Mime实体帮助类 (转载)
点击下载 MimeEntity.rar 这个类是关于Mime实体的类看下面代码吧 /// <summary> /// 类说明:Assistant /// 编 码 人:苏飞 /// 联系方式 ...
- java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
在使用Fragment的过程中,常常会遇到在Activity的onSaveInstanceState方法调用之后,操作commit或者popBackStack而导致的crash. 因为在onSaveI ...
- 关于AVD不能导入文件的解决方案
安卓虚拟机导入文件时报以下异常: [2013-01-23 16:09:18 - ddms] transfer error: Read-only file system [2013-01-23 16:0 ...
- MSSQL备份及数据迁移
版本:MSSQL 2008 备份情景:从A服务器的SQL 迁移到B服务器,并且数据也迁移过去. 操作环境:A服务器:WINDOWS7 B服务器:WINDOWS8.1 辅助工具:VNC 首先从A服 ...
- (转)iOS被开发者遗忘在角落的NSException-其实它很强大
转载自 http://www.jianshu.com/p/05aad21e319e iOS被开发者遗忘在角落的NSException-其实它很强大 字数597 阅读968 评论4 喜欢28 NSExc ...
- 【转】通用分页用户控件(DataGrid,DataList,Repeater都可以用它来分页)
通用分页控件(DataGrid,DataList,Repeater都可以用它来分页) 1.建立用户控件Pager.ascx 1.1 html </ASP:LABEL></TD> ...
- 读书笔记之 - javascript 设计模式 - 代理模式
代理(proxy)是一个对象,它可以用来控制对另一对象的访问.它与另外那个对象实现了同样的接口,并且会把任何方法调用传递给那个对象.另外那个对象通常称为本体.代理可以代替本体被实例化,并使其可被远程访 ...