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. [访问系统] Api_Win32_Mac类工具包 (转载)

    点击下载 Api_Win32_Mac.zip using System; using System.Collections.Generic; using System.Linq; using Syst ...

  2. ListView优化分页优化

    缘由 我们在用ListView展现数据的时候.比如展现联系人,如果联系人太多就会出现卡的现象,比如如果有1000多条数据,从数据库里查询,然后装载到List容器这段时间是比较耗时的.虽然我们可以用as ...

  3. 《将博客搬至CSDN》的文章

    我的CSDN地址 博客园应该以后会很少来了.

  4. Android - 获取字符串长度的宽度

    Paint paint = new Paint(); float strWidth = paint.measureText(String);

  5. .net下载文件方法

    1.以文件流下载 byte[] fileStr=new byte[5]; MemoryStream btMs = new MemoryStream(fileStr); //以字符流的形式下载文件 by ...

  6. PC110305/UVA10188

    根据我的规律,每天solved3题就感觉不行了~但是今天好像做水题做上瘾了,不过PC的题目尽管水,水得还是可以让人有进步. 这题OJ自动测评真心坑,题目看起来十分简单,测评返回三种可能: Accept ...

  7. eclipse下使用Genymotion调试Android程序出现的问题

    一. The connection to adb is down, and a severe error has occured. You must restart adb and Eclipse. ...

  8. jQuery.ajax() datatype:“json" 转换失败

    当使用jQuery.ajax() 时,如果设置dataType:"json",如果返回的字符转换出错则不会调用success方法,而进入error方法,控制台中也不会出现错误信息 ...

  9. Android Handler、Lopper消息驱动机制

    Android应用程序是通过消息来驱动的,系统为每一个应用程序维护一个消息队例(MesageQueue),应用程序的主线程不断地从这个消息队例中获取消息(Mesage),然后对这些消息进行处理(Han ...

  10. Dalvik虚拟机进程和线程的创建过程分析

    从前面Dalvik虚拟机的运行过程分析一文可以知道,Dalvik虚拟机除了可以执行Java代码之外,还可以执行Native代码,也就是C/C++函数. 这些C/C++函数在执行的过程中,又可以通过本地 ...