“科大讯飞杯”第18届上海大学程序设计联赛春季赛暨高校网络友谊赛 D-最大字符集 4.18

链接:https://ac.nowcoder.com/acm/contest/5278/D
来源:牛客网

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 524288K,其他语言1048576K
Special Judge, 64bit IO Format: %lld

题目描述

Cubercsl 很喜欢 01 字符串,就像“她喜欢大海”,这一天他想送她一个由 01 字符串组成的集合。
他自然是希望这个集合越多样化越大越好。所以他希望这个集合满足以下条件。
  • 每个字符串由 0 和 1 组成。
  • 每个字符串长度在 1 到 n 之间,且两两长度不同。
  • 集合中任何一个字符串都不是其他字符串的子串。
请你帮他找到满足他要求的最大的集合。
字符串 a 是 b 的子串当且仅当从 b 的头部和尾部删除一些字符(可以是零个或者所有)能得到的 a。

输入描述:

仅一行,包含一个整数 n(1≤n≤3001 \leq n \leq 3001n300)。

输出描述:

第一行输出这个集合的大小 k。
接下来 k 行每行输出一个 01 字符串,表示这个集合的一个元素。
答案不唯一,任何符合要求的答案都会被判为正确。
示例1

输入

1

输出

1
1
示例2

输入

5

输出

4
00
110
1010
11111

#include <iostream>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>//sort
#include <map>
#include <string>//map
#include<math.h>
using namespace std;
//找规律,使集合中任何一个字符串都不是其他字符串的子串,让0和1不交叉
//5: 11 101 1001 10001
int main()
{
    int n;
    cin>>n;
    if(n==1)//1和2为特殊情况
    {
        cout<<1<<endl<<1<<endl;
    }
    else if(n==2)
    {
        cout<<2<<endl<<0<<endl<<11<<endl;
    }
    else
    {
        cout<<n-1<<endl;
        for(int j=0; j<n-1; j++)
        {
            cout<<1;
            for(int i=0; i<j; i++)
            {
                cout<<0;
            }
            cout<<1<<endl;
        }
    }
}


posted @ 2020-04-19 11:39  SyrupWRLD  阅读(148)  评论(0)    收藏  举报