codeforce New Problem(dfs)

来源:互联网 发布:营销引流软件 编辑:程序博客网 时间:2024/06/07 06:26

题目链接:点击打开链接

Coming up with a new problem isn't as easy as many people think. Sometimes it is hard enough to name it. We'll consider a title original if it doesn't occur as a substring in any titles of recent Codeforces problems.

You've got the titles of n last problems — the strings, consisting of lowercase English letters. Your task is to find the shortest original title for the new problem. If there are multiple such titles, choose the lexicographically minimum one. Note, that title of the problem can't be an empty string.

substring s[l... r] (1 ≤ l ≤ r ≤ |s|) of string s = s1s2... s|s| (where |s| is the length of string s) is string slsl + 1... sr.

String x = x1x2... xp is lexicographically smaller than string y = y1y2... yq, if either p < q and x1 = y1, x2 = y2, ... , xp = yp, or there exists such number r (r < p, r < q), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 < yr + 1. The string characters are compared by their ASCII codes.

Input

The first line contains integer n (1 ≤ n ≤ 30) — the number of titles you've got to consider. Then follow n problem titles, one per line. Each title only consists of lowercase English letters (specifically, it doesn't contain any spaces) and has the length from 1 to 20, inclusive.

Output

Print a string, consisting of lowercase English letters — the lexicographically minimum shortest original title.

Examples
input
5threehorsesgoodsubstringssecretprimematrixbeautifulyear
output
j
input
4aabdefghijklmnopqrstuvwxyzc
output
ab
Note

In the first sample the first 9 letters of the English alphabet (a, b, c, d, e, f, g, h, i) occur in the problem titles, so the answer is letter j.

In the second sample the titles contain 26 English letters, so the shortest original title cannot have length 1. Title aa occurs as a substring in the first title.


题目大意:有n个字符串,每个字符串只有小写字母,不超过20个字符,n不大于30.求出一个字符串,这个字符串不是这n个字符串的字串,取最短的一个,若长度相等的话,取字典序最小的一个.

基本思路:dfs,这个题是在秋季集训的第一次测试做的,作为实验室最菜的我,一开始就思路错的,考虑的情况太少了,所以只能在补题时做了.不过一天之后还是自己做出来了.闲话少说.要想找到符合题意的字串,他会在不同长度的时候有很多种,比如:长度为三时,aaa,bbb.aba,等等都是,也就是说,每一位上都会有26中可能,因为要求字典序最小,那就从最小的开始查找即可,当字符串的长度为i时,就去暴力比较是不是那n个字符串的字串,如果不是就输出该字符串.(可能说的有点乱,具体看代码吧)

<span style="font-size:18px;">#include<cstring>#include<iostream>#include<cstdio>using namespace std;char str[50][50];char ch[50];int n;int f;void dfs(int top,int h){    if(f)return;    if(top>h)return;    if(top==h)    {        ch[top]='\0';        int flag=1;        for(int i=0;i<n;i++)        {            if(strstr(str[i],ch))            {                flag=0;            }        }        if(flag)        {            f=1;            cout<<ch<<endl;            return;        }    }    for(int i=0;i<26;i++)    {        ch[top]='a'+i;        dfs(top+1,h);    }}int main(){    while(cin>>n)    {        for(int i=0;i<n;i++)        {            cin>>str[i];        }        f=0;        for(int i=1;;i++)        {            dfs(0,i);            if(f)break;        }    }    return 0;}</span>


0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 老旧小区下水改造没改怎么办 替公司租房子中介不退押金怎么办 想在昆山找合租房的该怎么办 链家二手房价钱买贵了怎么办 拿私人房产证抵押借钱不还怎么办 在借贷宝里借钱不还怎么办 出租屋的大门感应钥匙弄丢了怎么办 法院拍卖的房子房主不配合怎么办 租的房子如果房主卖了怎么办 房东把门锁换了里面的东西怎么办 房租没到期房东把门锁换了怎么办 租了三年店面房东违反了合同怎么办 学生登录教务系统的密码忘记怎么办 铜陵无牌助力车被交警查到怎么办 福州超标电动车被交警抓到怎么办 单位自管公租房承租人去世怎么办 取得房产证后贷款批不下来怎么办 租店面遇到难搞的房东怎么办 在拆违通知书上签字了该怎么办 单位没交公职金的退休后怎么办 公租房合同到期后没有续签怎么办 租房合同没到期不想租了怎么办 租的房子是人家公租房怎么办 五险合一软件口令忘记了怎么办 计生办把婚育状况登记错了怎么办? 医院发票法院要保险也要怎么办 上海社保里生育险暂停参保怎么办? 痔疮手术后大姨妈来了怎么办 微创痔疮术后第五天涨出血怎么办? 肚子胀疼大便拉不出来怎么办 得痔疮了该怎么办昆明东大治 下体痒还没去检查就来月经了怎么办 直肠造口手术后造口肠子突出怎么办 痔疮pph手术瘢痕两年了该怎么办 肛瘘挂线术后六天腹泻了怎么办 刚满月的孩子鼻子不通气怎么办 齐鲁医院挂的号晚了怎么办 手机微信安装后注册失败怎么办 舞蹈基本功胸怎么都转不动怎么办 饥荒手机版第10天遇到的狗怎么办 饥荒海难手游石墙老是放歪怎么办