#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<math.h>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre(){freopen("c://test//input.in","r",stdin);freopen("c://test//output.out","w",stdout);}
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T> inline void gmax(T &a,T b){if(b>a)a=b;}
template <class T> inline void gmin(T &a,T b){if(b<a)a=b;}
const int N=0,M=0,Z=1e9+7,ms63=1061109567;
char s[105][1010];
int n;
int check(char s[],char x,char y)
{
int len=strlen(s);
for(int i=0;i<len;i++)if(s[i]!=x&&s[i]!=y)return 0;
return len;
}
int main()
{
while(~scanf("%d",&n))
{
int ans=0;
for(int i=1;i<=n;i++)scanf("%s",s[i]);
for(char x='a';x<='z';x++)
{
int tmp=0;
for(char y=x;y<='z';y++)
{
tmp=0;
for(int i=1;i<=n;i++)tmp+=check(s[i],x,y);
gmax(ans,tmp);
}
}
printf("%d\n",ans);
}
return 0;
}
/*
【题意】
给你n(100)个单词,
我们要选出其中若干个,
要求:
1,所有单词中最多只含有2种字符
2,在满足1的基础上使得这些单词的数量尽可能多
【类型】
暴力
【分析】
串很少,字符串最长很小,字符集也很少。
只选1或2个字符,那么我们暴力C(26,2)枚举吧。
然后再依次检验字符串即可
【时间复杂度&&优化】
O(26*26*1000)
*/
【Codeforces Round 329 (Div 2) A】【暴力枚举】2Char 选单词最多只含2字符
最新推荐文章于 2024-06-28 14:18:34 发布