HDU 4665 Unshuffle (2013多校6 1011 )

Unshuffle

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 148    Accepted Submission(s): 43
Special Judge


Problem Description
A shuffle of two strings is formed by interspersing the characters into a new string, keeping the characters of each string in order. For example, MISSISSIPPI is a shuffle of MISIPP and SSISI. Let me call a string square if it is a shuffle of two identical strings. For example, ABCABDCD is square, because it is a shuffle of ABCD and ABCD, but the string ABCDDCBA is not square.
Given a square string, in which each character occurs no more than four times, unshuffle it into two identical strings.
 

 

Input
First line, number of test cases, T.
Following are 2*T lines. For every two lines, the first line is n, length of the square string; the second line is the string. Each character is a positive integer no larger than n.

T<=10, n<=2000.
 

 

Output
T lines. Each line is a string of length n of the corresponding test case. '0' means this character belongs to the first string, while '1' means this character belongs to the second string. If there are multiple answers, output any one of them.
 

 

Sample Input
1 8 1 2 3 1 2 4 3 4
 

 

Sample Output
00011011
 

 

Source
 

 

Recommend
zhuyuanchen520
 
 
 
 
 
题解说的2-SAT,虽然比赛一直往这方面想,但是构图一直没有想出来。
 
 
只会暴力搜索过去。
 
T_T
 
dfs标记下就行了
 
 1 /*
 2  * Author:  kuangbin
 3  * File Name: 1011.cpp
 4  */
 5 #include <iostream>
 6 #include <stdio.h>
 7 #include <string.h>
 8 #include <algorithm>
 9 using namespace std;
10 
11 const int MAXN = 2020;
12 int a[MAXN];
13 int s[MAXN];
14 char ans[MAXN];
15 
16 bool flag ;
17 int n;
18 void dfs(int cur,int t1,int t2)
19 {
20     if(flag)return;
21     if(t1 > n/2 || t2 > n/2)return;
22     if(cur == n)
23     {
24         flag = true;
25         return;
26     }
27     s[t1] = a[cur];
28     ans[cur] = '0';
29     dfs(cur+1,t1+1,t2);
30     if(flag)return;
31     if(s[t2] == a[cur])
32     {
33         ans[cur] = '1';
34         dfs(cur+1,t1,t2+1);
35     }
36 }
37 
38 int main()
39 {
40     int T;
41     scanf("%d",&T);
42     while(T--)
43     {
44         scanf("%d",&n);
45         for(int i = 0;i < n;i++)
46             scanf("%d",&a[i]);
47         flag = false;
48         dfs(0,0,0);
49         for(int i = 0;i < n;i++)printf("%c",ans[i]);
50         printf("\n");
51     }
52     return 0;
53 }

 

 
 
 
 
 
 
 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值