Codeforces Beta Round #37 C. Old Berland Language 暴力 dfs
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的更多相关文章
- Codeforces Beta Round #37 B. Computer Game 暴力 贪心
B. Computer Game 题目连接: http://www.codeforces.com/contest/37/problem/B Description Vasya's elder brot ...
- Codeforces Beta Round #37 A. Towers 水题
A. Towers 题目连接: http://www.codeforces.com/contest/37/problem/A Description Little Vasya has received ...
- Codeforces Beta Round #1 C. Ancient Berland Circus 计算几何
C. Ancient Berland Circus 题目连接: http://www.codeforces.com/contest/1/problem/C Description Nowadays a ...
- Codeforces Beta Round #8 B. Obsession with Robots 暴力
B. Obsession with Robots 题目连接: http://www.codeforces.com/contest/8/problem/B Description The whole w ...
- 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 ...
- 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 ...
- Codeforces Beta Round #13 C. Sequence (DP)
题目大意 给一个数列,长度不超过 5000,每次可以将其中的一个数加 1 或者减 1,问,最少需要多少次操作,才能使得这个数列单调不降 数列中每个数为 -109-109 中的一个数 做法分析 先这样考 ...
- Codeforces Beta Round #5 B. Center Alignment 模拟题
B. Center Alignment 题目连接: http://www.codeforces.com/contest/5/problem/B Description Almost every tex ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
随机推荐
- 二、springcloud之熔断器hystrix
一.背景 雪崩效应 在微服务架构中通常会有多个服务层调用,基础服务的故障可能会导致级联故障,进而造成整个系统不可用的情况,这种现象被称为服务雪崩效应.服务雪崩效应是一种因“服务提供者”的不可用导致“服 ...
- python网络编程--线程GIL(全局解释器锁)
一:什么是GIL 在CPython,全局解释器锁,或GIL,是一个互斥体防止多个本地线程执行同时修改同一个代码.这把锁是必要的主要是因为当前的内存管理不是线程安全的.(然而,由于GIL存在,其他特性已 ...
- Python列表(list)
序列是Python中最基本的数据结构.序列中的每个元素都分配一个数字 - 它的位置,或索引,第一个索引是0,第二个索引是1,依此类推. 此外,Python已经内置确定序列的长度以及确定最大和最小的元素 ...
- 洛谷P2017晕牛
传送门啦 这个题没有想象中复杂. 我们先有向边建立,因为我们无法改变有向边的方向. 建立完之后跑一边拓扑排序,我们按拓扑序小的指向大的就好了. 解释: 我们知道如果一个点在另一个点顺序的后面的话,如果 ...
- CF312B 【Archer】
容易算出这人第一次胜利的概率,第二次的,第三次的…… 好像可以无限乘下去 但是这题精度卡到1e-6 不妨设一个eps,当这次胜率小于eps时,就break掉,反正它已经不影响答案了 我设的是eps=1 ...
- return to dl_resolve无需leak内存实现利用
之前在drop看过一篇文章,是西电的Bigtang师傅写的,这里来学习一下姿势做一些笔记. 0x01 基础知识 Linux ELF文件存在两个很重要的表,一个是got表(.got.plt)一个是plt ...
- Struts 2 Tutorial Basic MVC Architecture
Model View Controller or MVC as it is popularly called, is a software design pattern for developing ...
- mysql索引(btree索引和hash索引的区别)
所有MySQL列类型可以被索引.根据存储引擎定义每个表的最大索引数和最大索引长度.所有存储引擎支持每个表至少16个索引,总索引长度至少为256字节.大多数存储引擎有更高的限制. 索引的存储类型目前只有 ...
- Kubernetes监控:部署Heapster、InfluxDB和Grafana
本节内容: Kubernetes 监控方案 Heapster.InfluxDB和Grafana介绍 安装配置Heapster.InfluxDB和Grafana 访问 grafana 访问 influx ...
- LogStash plugins-inputs-file介绍(三)
官方文档 https://www.elastic.co/guide/en/logstash/current/plugins-inputs-file.html 重要参数: path # 文件路径 sin ...