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. barrier 和 preempt_disable() 学习【转】

    #define preempt_disable() \ do{ \ inc_preempt_count(); \ barrier();    \ }while(0) 一.这个barrier 在干什么. ...

  2. 测试mysqldump 压缩率和时间消耗

    测试mysqldump 压缩率和时间消耗 实验总结: 从本次实验数据可以看出,mysqldump通过|gzip参数可以将导出文件压缩53%,同时耗时也普通非压缩模式的2.3倍. 数据库环境: #[ro ...

  3. ie6下面不支持!important的处理方法

    例子: #box {      color:red !important;      color:blue;  } 这个例子应该是大家经常见到的important的用法了,在IE6环境下,这行字是蓝色 ...

  4. linux命令(10):ps命令

    1.查看mysql进程数: ps -ef | grep "mysql" | grep -v "grep" | wc –l 2.监控CPU状态:ps –au 3. ...

  5. BestCoder Round #86 二,三题题解(尺取法)

    第一题太水,跳过了. NanoApe Loves Sequence题目描述:退役狗 NanoApe 滚回去学文化课啦! 在数学课上,NanoApe 心痒痒又玩起了数列.他在纸上随便写了一个长度为 nn ...

  6. Java学习笔记(十三)——通过Netbeans开发环境生成oracle数据库中表的对应hibernate映射文件

    [前面的话] 身体慢慢已经快好了,感觉真好,哈哈. 这篇文章要通过Hibernate对数据库进行操作,而Netbeans可以直接通过数据库逆向生成对应的映射文件.基础文章,选择性阅读. [步骤] 1. ...

  7. (翻译)一起使用 .NET 和 Docker——DockerCon 2018 更新

    原文:https://blogs.msdn.microsoft.com/dotnet/2018/06/13/using-net-and-docker-together-dockercon-2018-u ...

  8. vue分页tbale小荔枝

    首先,动态加载数据 <table class="table table-bordered table-condensed no_margin_bottom jyjg_tab" ...

  9. #1054 - Unknown column 'category' in 'field list'

    导致这个问题的原因有: 1.确实没有这个字段 2.写错表了,你以为写到想要的表,没想到写到别处去了,当然没有这个字段了,这时候检查一下sql语句是不是选错了表,或者选错了数据库

  10. 2018 ACM-ICPC 青岛网络赛

    最近打比赛不知道为什么总是怀疑自己 写完之后不敢交,一定跟学长说一遍自己的思路 然后发现"哦原来我是对的" 然后就A掉了…… 所以还是要有自信 Problem A 最大值直接输出m ...