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

Problem Description
I like playing game with my friend, although sometimes looks pretty naive. Today I invent a new game called LianLianKan. The game is about playing on a number stack.
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.
 
Input
There are multiple test cases.
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)
 
Output
For each test case, output “1” if I can pop all elements; otherwise output “0”.
 
Sample Input
2
1 1
3
1 1 1
2
1000000 1
 
Sample Output
1
0
0
 #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的更多相关文章

  1. hdu 4272 LianLianKan 状态压缩

      LianLianKan Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  2. HDU 4272 LianLianKan (状压DP+DFS)题解

    思路: 用状压DP+DFS遍历查找是否可行.假设一个数为x,那么他最远可以消去的点为x+9,因为x+1~x+4都能被他前面的点消去,所以我们将2进制的范围设为2^10,用0表示已经消去,1表示没有消去 ...

  3. HDU 4272 LianLianKan(状压DP)题解

    题意:一个栈,每次可以选择和栈顶一样的数字,并且和栈顶距离小于6,然后同时消去他们,问能不能把所有的数消去 思路:一个数字最远能消去和他相距9的数,因为中间4个可以被他上面的消去.因为还要判断栈顶有没 ...

  4. LianLianKan - HDU 4272(状态压缩)

    题目大意:有一列数据,可以从最上面的开始连接下面相同的元素,然后消除,不过距离不能超过6,询问最后能不能消除完整个数列. 分析:首先讨论一点最远能消除的地方,比如点的位置是x,如若想要消除x+1位置处 ...

  5. LianLianKan HDU - 4272 状压dp

    题意:长度为n(n<=1000)的栈,栈顶元素可以与下面1~5个数中相同的元素消去,问最后能都完全消去. 题解: 比如这个序列12345678910112这个位置的最远可匹配位置能到11为什么呢 ...

  6. hdoj 4272 LianLianKan 数据太水

    LianLianKan Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  7. hdu 4272 2012长春赛区网络赛 dfs暴力 ***

    总是T,以为要剪枝,后来发现加个map就行了 #include<cstdio> #include<iostream> #include<algorithm> #in ...

  8. 2012年长春网络赛(hdu命题)

    为迎接9月14号hdu命题的长春网络赛 ACM弱校的弱菜,苦逼的在机房(感谢有你)呻吟几声: 1.对于本次网络赛,本校一共6名正式队员,训练靠的是完全的自主学习意识 2.对于网络赛的群殴模式,想竞争现 ...

  9. HDU 1695 GCD (欧拉函数+容斥原理)

    GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

随机推荐

  1. wcf入门教程

    一.概述 Windows Communication Foundation(WCF)是由微软发展的一组数据通信的应用程序开发接口,可以翻译为Windows通讯接口,它是.NET框架的一部分.由 .NE ...

  2. AcroExch.Rect 单位、属性问题

    AcroExch.Rect  有四个属性:Top,Right,Left,Buttom 1.单位:point,一般通过英寸换算,1point=1/72 inch(英寸) 2.属性:Top: 区域距离 x ...

  3. Oracle学习【语句查询】

    基本查询语句any和all不能单独使用,必须和比较符一起使用>any 大于最小的例如:select * from emp where sal >any(1000,2000);<any ...

  4. 4.SQL语言基础

    4.1语言分类和用户模式 4.1.1语言分类 1)数据查询语言 用语检索数据库中的数据,主要是select语句,是操作数据库时最为频繁使用. 2)数据操纵语言 用语改变数据库中的数据,主要包括inse ...

  5. Java基础--Java内存管理与垃圾回收

      Java自动内存管理 在讲解内存管理之前,首先需要了解对象和对象引用的区别 对象是类的一个实例,以人这个类为例,Person是我们定义的一个类 public class Person{} publ ...

  6. cmd 进入不同的驱动盘及上下级目录

    “开始”=>“运行”,输入”cmd“,此时进入的是系统管理员的等待命令 如果想进入相应的盘符,如 d 盘,则输入 cd d:\,然后再次输入 d: 即可进入 d: 盘,输入两次相当于第二在是询问 ...

  7. node.Js学习-- 创建服务器简要步骤

    1.创建项目目录 mkdir ningha(文件夹名)npm init 初始化项目  获得package.json 2..在node.Js命令行操作进入到文件所在目录 3.输入browser-sync ...

  8. JavaScript学习心得(三)

    一 变量 var:变量声明 变量名 =:赋值 简单值类型 全局变量:编程的一般规则——应用程序应该只完成必须的最少功能,如果一个变量不是绝对必需,就不该是全局:全局变量对维护性能不利,因为需要一直维护 ...

  9. node 后台ajax文件(同时支持http、https)

    var http = require("http"), Url = require("url"), querystring = require('queryst ...

  10. iOS: 神奇的addSubView

    看着addSubView, 本以为是添加多个对象, 但通过测试代码, 发现同一个对象在addSubView中只会添加一次. 想想, 视图对象是通过引用得到的. 在视图的子视图集中, 只保存一个相应的对 ...