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标记下就行了
 
 /*
* Author: kuangbin
* File Name: 1011.cpp
*/
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; const int MAXN = ;
int a[MAXN];
int s[MAXN];
char ans[MAXN]; bool flag ;
int n;
void dfs(int cur,int t1,int t2)
{
if(flag)return;
if(t1 > n/ || t2 > n/)return;
if(cur == n)
{
flag = true;
return;
}
s[t1] = a[cur];
ans[cur] = '';
dfs(cur+,t1+,t2);
if(flag)return;
if(s[t2] == a[cur])
{
ans[cur] = '';
dfs(cur+,t1,t2+);
}
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i = ;i < n;i++)
scanf("%d",&a[i]);
flag = false;
dfs(,,);
for(int i = ;i < n;i++)printf("%c",ans[i]);
printf("\n");
}
return ;
}
 
 
 
 
 
 
 

HDU 4665 Unshuffle (2013多校6 1011 )的更多相关文章

  1. HDU 4642 Fliping game (2013多校4 1011 简单博弈)

    Fliping game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  2. HDU 4631 Sad Love Story (2013多校3 1011题 平面最近点对+爆搞)

    Sad Love Story Time Limit: 40000/20000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others ...

  3. HDU 4970(杭电多校#9 1011题)Killing Monsters(瞎搞)

    题目地址:HDU 4970 先进行预处理.在每一个炮塔的火力范围边界标记一个点. 然后对每一个点的伤害值扫一遍就能算出来. 然后在算出每一个点到终点的总伤害值,并保存下来,也是扫一遍就可以. 最后在询 ...

  4. HDU/杭电2013多校第三场解题报告

    今天悲剧了,各种被虐啊,还是太年轻了 Crime 这道题目给的时间好长,第一次就想到了暴力,结果华丽丽的TLE了. 后来找了一下,发现前24个是1, 2, 6, 12, 72, 72, 864, 17 ...

  5. HDU 4665 Unshuffle DFS找一个可行解

    每层找一对相等的整数,分别放在两个不同的串中. 参考了学弟的解法,果断觉得自己老了…… #include <cstdio> #include <cstring> #includ ...

  6. HDU 4758 Walk Through Squares (2013南京网络赛1011题,AC自动机+DP)

    Walk Through Squares Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Oth ...

  7. HDU 4705 Y (2013多校10,1010题,简单树形DP)

    Y Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submiss ...

  8. HDU 4704 Sum (2013多校10,1009题)

    Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submi ...

  9. HDU 4699 Editor (2013多校10,1004题)

    Editor Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Su ...

随机推荐

  1. Development tools[重点]

    Development tools yum groupinfo "Development tools" Loaded plugins: product-id, security, ...

  2. 在64位linux下编译32位程序

    在64位linux下编译32位程序 http://blog.csdn.net/xsckernel/article/details/38045783

  3. git - 开发者电脑与服务器的配置

    首先公司要有一台git服务器,现在一般都托管在github服务器上,在中国可能会托管到oschina上,oschina有一点好处就是可以免费托管私有项目,而在github上想要托管自己的项目是收费的, ...

  4. JavaScript原型与继承(1)

    内容: 创建对象的几种模式以及创建的过程 原型链prototype的理解,以及prototype与 __proto__([[Prototype]])的关系 继承的几种实现 1.常见模式与原型链的理解 ...

  5. MySQL5.6.32源码安装

      . 安装好--安装MySQL需要的包 yum install -y autoconf automake imake libxml2-devel expat-devel cmake gcc gcc- ...

  6. ArcGIS Server 基于Token安全验证

    写在前面:只使用token并不能起到安全验证的作用,ArcGIS Server文件夹的权限是开放的,我们不需要登录Server平台即可访问服务,所以我们应该将Token验证和文件夹的安全性结合起来使用 ...

  7. Linux 各个版本之间的差别

    一直没有搞清楚RHEL,CentOS,,还有Ubuntu,fedora这些版本之间的差别,搜了一下,整理到这里,备忘吧. 我最关心的: 1, CentOS是在RHEL基础上的免费版: 2, Ubunt ...

  8. JQuery判断一个元素下面是否有内容或者有某个标签

    网站开发时,我们时常需要把没有内容的标签隐藏或者去掉.在用JQ有两种好的解决办法: 一.判断文本是否为空 var jqObj = $(this);if(jqObj.text().trim()){ // ...

  9. JVM 类加载过程、初始化、主动引用、被动引用、静态初始化块执行顺序

  10. 机器学习方法(七):Kmeans聚类K值如何选,以及数据重抽样方法Bootstrapping

    欢迎转载,转载请注明:本文出自Bin的专栏blog.csdn.net/xbinworld. 技术交流QQ群:433250724,欢迎对算法.技术感兴趣的同学加入.我的博客写一些自己用得到东西,并分享给 ...