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

31 2 3

Output

YES010110

Input

31 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;
}

原文地址:https://www.cnblogs.com/ww123/p/8490356.html

时间: 2024-10-29 14:56:24

Old Berland Language的相关文章

瞎翻译啊 CodeForces 41A - Translation

The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For

Codeforces-Translation(水题)

The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For

A - Translation

Problem description The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronoun

Educational Codeforces Round 21 G. Anthem of Berland(dp+kmp)

题目链接:Educational Codeforces Round 21 G. Anthem of Berland 题意: 给你两个字符串,第一个字符串包含问号,问号可以变成任意字符串. 问你第一个字符串最多包含多少个第二个字符串. 题解: 考虑dp[i][j],表示当前考虑到第一个串的第i位,已经匹配到第二个字符串的第j位. 这样的话复杂度为26*n*m*O(fail). fail可以用kmp进行预处理,将26个字母全部处理出来,这样复杂度就变成了26*n*m. 状态转移看代码(就是一个kmp

【翻译】Android Interface Definition Language (AIDL)

参考地址:https://developer.android.com/guide/components/aidl.html Android Interface Definition Language (AIDL) AIDL (Android Interface Definition Language) is similar to other IDLs you might have worked with. It allows you to define the programming inter

Go语言自述(The Go Programming Language README)

声明:本文为笔者为练习英语所做的翻译练习,原文所属者与笔者没有任何关系,翻译结果不代表原文所属者的观点.笔者不保证翻译的正确性,任何人以任何形式的对本文的引用,都是不负责任和荒谬的行为,造成的后果笔者不予负责. 原文链接所属:golang/go Go is an open source programming language that makes it easy to build simple,reliable, and efficient software. Go是一门开源的编程语言,用它可

Codeforces 808G. Anthem of Berland

G. Anthem of Berland 题意:给两串S,T.S由"a-z","?"组成,T由"a-z"组成.你可以钦定这些"?",询问 T 在 S 中最多出现次数. 想法:考虑Dp,需要记录的是匹配到 T 多长的前缀.于是设$F[i][j]$表示 S 前 j 位现匹配 T 前i位的最多完整匹配次数.转移需要求出$nx[i][v]$表示 T 前i位后面接上v能匹配的最长前缀,用KMP求一下. Code #include <

Mysql DCL (Date Control Language)

Mysql DCL (Date Control Language) 数据库:mysql> select * from fen; +-------+-------+---------+ | name | china | english | +-------+-------+---------+ | ming | 69 | 99 | | hong | 48 | 33 | | qiang | 77 | 33 | +-------+-------+---------+ 3 rows in set (0.

窝上课不听,how to learn C language easily(1)

C language 学习心得 附:为啥起这么霸气侧漏,招大神们鄙视的标题,正如我在<C language>随笔的介绍中写的,这是一个写个妹纸们看的C language的文章.没错!!写这篇文章的灵感也来自于上周Clanguage课上偶撩到一个连书包都不放下在玩手机的妹子(普通聊天而已,嘘~~~),得知她课后在自学慕课,刚看到数组·····那得有多慢!于是,小子虽不才,但正义感十足,决心写一章超级宇宙无敌简单入门炫酷无敌吊炸天的C language 入门指南. 其实,鄙人大一上受了大神Alex