Old Berland Language

Posted ww123

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
#include <iostream>
using namespace std;
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>
#include <cmath>
struct node
{
    string s;
    int len;
    int id;
}a[1005];
int pos=0,n,flag=0;
bool cmp(struct node a,struct node b)
{
    if(a.len<b.len)
        return true;
    return false;
}
void dfs(int t,string x)
{
  if(t==a[pos].len){
    a[pos].s=x;
    pos++;
    if(pos==n)
        flag=1;
    return;
  }
  dfs(t+1,x+0);
  if(pos==n)
  return;
  dfs(t+1,x+1);
}
bool cmp1(struct node a,struct node b)
{
    if(a.id<b.id)
        return true;
    return false;
}
int main()
{
    int m,i,j,k;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a[i].len;
        a[i].id=i;
        a[i].s="";
    }
    sort(a,a+n,cmp);
    dfs(0,"");
    if(flag){
        cout<<"YES"<<endl;
        sort(a,a+n,cmp1);
    for(i=0;i<n;i++)
        cout<<a[i].s<<endl;
    }
    else
        cout<<"NO"<<endl;
}

 

以上是关于Old Berland Language的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces 723D. Lakes in Berland

CF723D Lakes in Berland

Codeforces 1296F Berland Beauty(思维,图)

CodeForces 723D Lakes in Berland (dfs搜索)

Educational Codeforces Round 108 (Rated for Div. 2)-C. Berland Regional-题解

将微调器值从片段传递到活动