Skip to content

Instantly share code, notes, and snippets.

@rve
Created March 1, 2013 00:47
Show Gist options
  • Save rve/5061522 to your computer and use it in GitHub Desktop.
Save rve/5061522 to your computer and use it in GitHub Desktop.
cf_170_div2_2
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<set>
#define MAXN 21
#define INF 0x3f3f3f3f
using namespace std;
int n;
int maxm;
string m[MAXN+10];
char str[23];
string ans = "zzzzzzzzzzzzzzzzzzzz";
bool notsub(string a)
{
for(int i=0; i<n; i++)
{
if (m[i].find(a) != string::npos)
{
return false;
}
}
return true;
}
void dfs(char * a, int n)
{
if (n == maxm )
{
if (notsub(a))
{
if (string(a).size() <= ans.size() && string(a) < ans)
{
ans = string(a);
}
}
return;
}
for(int i=0; i<26; i++)
{
a[n] = 'a' + i;
dfs(a, n+1);
}
}
int main()
{
//freopen("test.in", "r", stdin);
cin>>n;
for(int i=0; i<n; i++)
cin>>m[i];
//maxm = max_non();
for(maxm = 1; maxm<5; maxm++)
for(int i=0; i<26; i++)
{
char a[MAXN];
memset(a, '\0', sizeof(a));
a[0] = 'a' + i;
dfs(a, 1);
}
cout<<ans<<endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment