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 现在你已经有一 ...
随机推荐
- C#匿名函数与Lambda表达式
Lambda 表达式是一种可用于创建委托或表达式目录树类型的匿名函数. 通过使用 lambda 表达式,可以写入可作为参数传递或作为函数调用值返回的本地函数.在C#中的Linq中的大部分就是由扩展方法 ...
- ORACLE表空间查询和管理【转】
红色是自由指定的~~--查询表空间SELECT D.TABLESPACE_NAME, SPACE "SUM_SPACE(M)", SPACE - NVL(F ...
- HDU 6203 2017沈阳网络赛 LCA,DFS+树状数组
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6203 题意:n+1 个点 n 条边的树(点标号 0 ~ n),有若干个点无法通行,导致 p 组 U V ...
- java基础41 枚举(类)
1.概述 枚举:一些方法在运行时,它需要数据不能是任意的,而必须是一定范围内的值,可以使用枚举解决 2.枚举的格式 enum 类名{ 枚举值 } 例子 package com.dhb.enumerat ...
- Kubernetes之YAML文件
一.YAML 基础 YAML是专门用来写配置文件的语言,非常简洁和强大,使用比json更方便.它实质上是一种通用的数据串行化格式.后文会说明定义YAML文件创建Pod和创建Deployment. YA ...
- .gitignore文件如何编写?
.gitignore文件即 项目中不需要被追踪(track)且上传到git系统的文件 <1>忽略文件的原则 a.忽略操作系统自动生成的文件,比如缩略图等 b.忽略编译生成的中间文件.可执行 ...
- 关于C语言的几个考试编程题目
提交要求:1:邮件名称:学号后三位-题目编号-姓名-期中考试.例如:098-1-沈苗-期中考试2:不用附件提交,直接写邮件,内容包括编程思路(写一段自己对题目的认识.思路.技术细节等).源代码.运行结 ...
- 【LOJ】#6391. 「THUPC2018」淘米神的树 / Tommy
题解 一道非常神仙的计数题 如果只有一个点,就是非常简单的树型dp \(f_{u} = (siz_{u} - 1)! \prod_{v \in son_{u}} \frac{f_{v}}{siz_{v ...
- 【LOJ】#2587. 「APIO2018」铁人两项
题解 学习了圆方树!(其实是复习了Tarjan求点双) 我又双叒叕忘记了tarjan点双一个最重要,最重要的事情! 就是--假如low[v] >= dfn[u],我们就找到了一个点双,开始建立方 ...
- Python下opencv使用笔记(图像的平滑与滤波)
对于图形的平滑与滤波,但从滤波角度来讲,一般主要的目的都是为了实现对图像噪声的消除,增强图像的效果. 对于2D图像可以进行低通或者高通滤波操作 低通滤波(LPF):有利于去噪,模糊图像 高通滤波(HP ...