Old Berland Language

Old Berland Language

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, 0and 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.

Example

Input
3
1 2 3
Output
YES
0
10
110
Input
3
1 1 1
Output
NO

咸鱼如我看到的第一瞬间是懵逼的。最后在题解的帮助下发现了做法π__π。这道题是用dfs查找出符合长度条件的字符串。菜鸡完全届不到。
#include<bits/stdc++.h>
#define maxn 1010
typedef long long ll;
using namespace std;
int n,num=0;
bool f=0;
struct node{
  int l;
  int m;
  string str;};
struct node a[maxn];
bool cmp(node a,node b)
{
    return a.l<b.l;
}
bool cmp1(node a,node b)
{
    return a.m<b.m;
}
void dfs(int x,string s)
{
    if(x==a[num].l)
    {
        a[num].str=s;
        num++;
        if(num==n)
            f=1;
        return ;
    }
    dfs(x+1,s+'0');
    if(num==n) return;
    dfs(x+1,s+'1');

}
//字符串从尾部开始改变,0->1,保证相近的字符串在较小的一个的尾部不同,从而保证前者不会成为成为后者的子序列。
int main() { cin>>n; for(int i=0;i<n;i++) { cin>>a[i].l; a[i].m=i; a[i].str=""; } sort(a,a+n,cmp);//按照字符串长度要求排序 dfs(0,""); if(!f) cout<<"NO"<<endl; else { cout<<"YES"<<endl; sort(a,a+n,cmp1);//回复成原来的顺序 for(int i=0;i<n;i++) cout<<a[i].str<<endl; } }

 


原题链接:http://codeforces.com/problemset/problem/37/C

转载于:https://www.cnblogs.com/saltyfishinwind/p/8600784.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值