LianLianKan
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2884 Accepted Submission(s): 898
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
题意
给你一个队列,然后每个子可以和距离为以内的子连接,然后这两个子都pop,然后问你,是否这个队列能够全部pop掉
题解
数据太水了,判一判子的个数是否为偶数,然后再判断是否每一类都是偶数,然后直接输出1,然后就A了= =
标答应该是一个状态压缩DP
LL a[maxn]; int vis[maxn]; int flag=0; map<int,int> kiss; int n; void dfs(int nn,int cur) { if(nn>n) return; if(vis[nn]==1) dfs(nn+1,cur); if(cur==n) { flag=1; return; } int m=nn; REP_1(i,5) { m++; while(1) { if(m>n) return; if(vis[m]==0) break; m++; } if(a[m]==a[nn]) { vis[nn]=1; vis[m]=1; dfs(nn+1,cur+2); vis[nn]=0; vis[m]=0; } } } int main() { while(RD(n)!=-1) { memset(vis,0,sizeof(vis)); kiss.clear(); REP_1(i,n) { RD(a[i]); kiss[a[i]]++; } if(n%2==1) { flag=0; printf("0\n"); continue; } int flag2=1; REP_1(i,n) { if(kiss[a[i]]%2==1) { flag2=0; break; } } if(flag2==0) { printf("0\n"); continue; } //dfs(1,0); cout<<"1"<<endl; } }