C. Old Berland Language

题目连接:

http://www.codeforces.com/contest/37/problem/C

Description

Berland scientists know that the Old Berland language had exactly n words. Those words had lengths of l1, l2, ..., ln letters. Every word consisted of two letters, 0 and 1. Ancient Berland people spoke quickly and didn’t make pauses between the words, but at the same time they could always understand each other perfectly. It was possible because no word was a prefix of another one. The prefix of a string is considered to be one of its substrings that starts from the initial symbol.

Help the scientists determine whether all the words of the Old Berland language can be reconstructed and if they can, output the words themselves.

Input

The first line contains one integer N (1 ≤ N ≤ 1000) — the number of words in Old Berland language. The second line contains N space-separated integers — the lengths of these words. All the lengths are natural numbers not exceeding 1000.

Output

If there’s no such set of words, in the single line output NO. Otherwise, in the first line output YES, and in the next N lines output the words themselves in the order their lengths were given in the input file. If the answer is not unique, output any.

Sample Input

3

1 2 3

Sample Output

YES

0

10

110

Hint

题意

有n个串,并且每个串的长度为p[i]

你需要构造出这n个串,并且这n个串互相不为其他串的前缀

问你是否能够构造出来

不能输出no

题解:

直接dfs一波,就莽过去了……

复杂度很显然是最多往下面搜1000层吧……

感觉分支不是很多的样子

233

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1005;
int n;
struct node
{
int x,y;
string ans;
}p[maxn];
int now,ok;
bool cmp(node a,node b)
{
return a.x<b.x;
}
bool cmp2(node a,node b)
{
return a.y<b.y;
}
void dfs(int x,string s)
{
if(x==p[now].x)
{
p[now++].ans=s;
if(now==n)ok=1;
return;
}
dfs(x+1,s+'0');
if(now==n)return;
dfs(x+1,s+'1');
if(now==n)return;
}
int main()
{
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d",&p[i].x);
p[i].y=i;
p[i].ans="";
}
sort(p,p+n,cmp);
dfs(0,"");
if(!ok)printf("NO\n");
else{
printf("YES\n");
sort(p,p+n,cmp2);
for(int i=0;i<n;i++)
cout<<p[i].ans<<endl;
}
}

Codeforces Beta Round #37 C. Old Berland Language 暴力 dfs的更多相关文章

  1. Codeforces Beta Round #37 B. Computer Game 暴力 贪心

    B. Computer Game 题目连接: http://www.codeforces.com/contest/37/problem/B Description Vasya's elder brot ...

  2. Codeforces Beta Round #37 A. Towers 水题

    A. Towers 题目连接: http://www.codeforces.com/contest/37/problem/A Description Little Vasya has received ...

  3. Codeforces Beta Round #1 C. Ancient Berland Circus 计算几何

    C. Ancient Berland Circus 题目连接: http://www.codeforces.com/contest/1/problem/C Description Nowadays a ...

  4. Codeforces Beta Round #8 B. Obsession with Robots 暴力

    B. Obsession with Robots 题目连接: http://www.codeforces.com/contest/8/problem/B Description The whole w ...

  5. Codeforces Beta Round #87 (Div. 2 Only)-Party(DFS找树的深度)

    A company has n employees numbered from 1 to n. Each employee either has no immediate manager or exa ...

  6. Codeforces Beta Round #22 (Div. 2 Only) E. Scheme dfs贪心

    E. Scheme   To learn as soon as possible the latest news about their favourite fundamentally new ope ...

  7. Codeforces Beta Round #13 C. Sequence (DP)

    题目大意 给一个数列,长度不超过 5000,每次可以将其中的一个数加 1 或者减 1,问,最少需要多少次操作,才能使得这个数列单调不降 数列中每个数为 -109-109 中的一个数 做法分析 先这样考 ...

  8. Codeforces Beta Round #5 B. Center Alignment 模拟题

    B. Center Alignment 题目连接: http://www.codeforces.com/contest/5/problem/B Description Almost every tex ...

  9. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

随机推荐

  1. 【HASPDOG】hasp_update参数f和i区别

    [root@BICServer-TX shared]# ./hasp_update This is a simple demo program for the Sentinel Update and ...

  2. 【HASPDOG】Communication error

    靠,防火墙没关,关了防火墙生成文件成功

  3. Using KernelShark to analyze the real-time scheduler【转】

    转自:https://lwn.net/Articles/425583/ This article brought to you by LWN subscribers Subscribers to LW ...

  4. python几种装饰器的用法

    用函数装饰函数 这种比较常见首先定义装饰器函数 def cache(func): data = {} @wraps(func) def wrapper(*args, **kwargs): key = ...

  5. 三、springcloud之服务调用Feign

    一.背景 项目中接口调用: Httpclient Okhttp Httpurlconnection RestTemplate 微服务提供了更简单,方便的Feign 二.Feign简介 Feign是一个 ...

  6. 洛谷P1938 找工就业

    传送门啦 这个题本质就是跑一边最长路,重点就是在怎么建图上. 我们可以把点权放到边权上面,即将每一个边的终点点权当做这个边的边权,这个题里就是将工钱 $ d $ 当做边权. 如果这一条边需要坐飞机才能 ...

  7. python软件依赖关系

    caffe:numpy,scikit-image opencv:numpy

  8. Git missing in VS Code – No source control providers

    解决办法:管理->设置->搜索[git.enabled]和[git.path],分别设置下即可. 注意"git.enabled: true",只设置git.path是不 ...

  9. js中的call,apply,bind区别

    在JavaScript中,call.apply和bind是Function对象自带的三个方法,这三个方法的主要作用是改变函数中的this指向. call.apply.bind方法的共同点和区别:app ...

  10. 学习Java你必须了解的知识

    1.什么是Java虚拟机?为什么Java被称作是平台无关的编程语言? Java虚拟机是一个可以执行Java字节码的虚拟机进程.Java源文件被编译成能被Java虚拟机执行的字节码文件.Java应用程序 ...