CodeForces - 593A -2Char(思维+暴力枚举)
Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is that each of them uses at most two distinct letters. Andrew decided to send an article to the magazine, but as he hasn't written any article, he just decided to take a random one from magazine 26Char. However, before sending it to the magazine 2Char, he needs to adapt the text to the format of the journal. To do so, he removes some words from the chosen article, in such a way that the remaining text can be written using no more than two distinct letters.
Since the payment depends from the number of non-space characters in the article, Andrew wants to keep the words with the maximum total length.
Input
The first line of the input contains number n (1 ≤ n ≤ 100) — the number of words in the article chosen by Andrew. Following are n lines, each of them contains one word. All the words consist only of small English letters and their total length doesn't exceed 1000. The words are not guaranteed to be distinct, in this case you are allowed to use a word in the article as many times as it appears in the input.
Output
Print a single integer — the maximum possible total length of words in Andrew's article.
Examples
Input
4
abb
cacc
aaa
bbb
Output
9
Input
5
a
a
bcbcb
cdecdecdecdecdecde
aaaa
Output
6
Note
In the first sample the optimal way to choose words is {'abb', 'aaa', 'bbb'}.
In the second sample the word 'cdecdecdecdecdecde' consists of three distinct letters, and thus cannot be used in the article. The optimal answer is {'a', 'a', 'aaaa'}.
对于这个题,我们的做法是把26个字母任取两个进行枚举,看在字符串中那些最多
代码:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
string str[105];
int main()
{
int n;
cin>>n;
for(int t=0;t<n;t++)
{
cin>>str[t];
}
int sum;
int maxn=0;
for(int i='a';i<='z';i++)
{
for(int j=i;j<='z';j++)
{ sum=0;
for(int k=0;k<n;k++)
{
int len=str[k].length();
int m;
for( m=0;m<len;m++)
{
if(str[k][m]!=i&&str[k][m]!=j)
{
break;
}
}
if(m==len)
{
sum+=len;
}
}
maxn=max(maxn,sum);
}
}
cout<<maxn<<endl;
return 0;
}
CodeForces - 593A -2Char(思维+暴力枚举)的更多相关文章
- CodeForces - 1244D (思维+暴力)
题意 https://vjudge.net/problem/CodeForces-1244D 有一棵树,有3种颜色,第i个节点染成第j种颜色的代价是c(i,j),现在要你求出一种染色方案,使得总代价最 ...
- Codeforces 626E Simple Skewness(暴力枚举+二分)
E. Simple Skewness time limit per test:3 seconds memory limit per test:256 megabytes input:standard ...
- codeforces Restore Cube(暴力枚举)
/* 题意:给出立方体的每个顶点的坐标(是由源坐标三个数某几个数被交换之后得到的!), 问是否可以还原出一个立方体的坐标,注意这一句话: The numbers in the i-th output ...
- codeforces 700C Break Up 暴力枚举边+边双缩点(有重边)
题意:n个点,m条无向边,每个边有权值,给你 s 和 t,问你至多删除两条边,让s,t不连通,问方案的权值和最小为多少,并且输出删的边 分析:n<=1000,m是30000 s,t有4种情况( ...
- Diverse Garland CodeForces - 1108D (贪心+暴力枚举)
You have a garland consisting of nn lamps. Each lamp is colored red, green or blue. The color of the ...
- CodeForces 496D Tennis Game (暴力枚举)
题意:进行若干场比赛,每次比赛两人对决,赢的人得到1分,输的人不得分,先得到t分的人获胜,开始下场比赛,某个人率先赢下s场比赛时, 游戏结束.现在给出n次对决的记录,问可能的s和t有多少种,并按s递增 ...
- CodeForces 593A 2Char
暴力. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> u ...
- Codeforces 327A-Flipping Game(暴力枚举)
A. Flipping Game time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- CodeForces - 1230C(思维/暴力)
题意 https://vjudge.net/problem/CodeForces-1230C 给了你总共有21张多米诺骨牌,每张牌有两个面,然后给你一个无向图,保证没有环和一个顶点多条边的情况存在.现 ...
随机推荐
- #pragma execution_character_set("utf-8")
VC2010增加了“#pragma execution_character_set("utf-8")”,指示char的执行字符集是UTF-8编码. VS2010 设置 字符编码: ...
- SpringBoot表单验证
需求:年龄在18岁以下的女生不能注册 处理器中的写法: 实体类中的写法:
- cocos2d中setBlendFunc设置颜色混合方案
CCSprite有一个ccBlendFunc类型的blendFunc_结构体成员,可以用来设置描绘时的颜色混合方案.ccBlendFunc包含了一个src和一个dst,分别表示源和目标的运算因子. 如 ...
- linux中的管道命令
很有用的一个命令,用法如下: A | B 是把A命令的输出作为B命令的输入. 比如我想查看一下我在终端输入过的命令,可以这样: history | less
- Linux tput命令
一.简介 shell 脚本编写者往往需要能通过一种方法将输出更改为粗体,为其加下划线,实现反向突出显示等,这正是 tput 的用武之地. tput 命令将通过 terminfo 数据库对您的终端会话进 ...
- noi.ac day1t3 Sort
传送门 分析 快排的原理是以任意一个数为标准,然后把所有小于它的数换到它的左边,所有大于它的数换到它的右边.我们就使用快排的思路,分治整个区间.对于每个区间以排好序的这个数列的中间位置的值为标准,然后 ...
- 2013年第四届蓝桥杯国赛 九宫重排(HashMap+双BFS优化)
九宫重排 时间限制:1.0s 内存限制:256.0MB 问题描述 如下面第一个图的九宫格中,放着 1~8 的数字卡片,还有一个格子空着.与空格子相邻的格子中的卡片可以移动到空格中.经过若干 ...
- Mac常用开发工具
1.svn客户端 SVN client SmartSVN 2.git客户端 SourceTree | Free Git GUI for Mac and Windows 3.远程windows系统工具( ...
- chrome安装postman插件
参考http://www.cnplugins.com/zhuanti/how-to-make-crx-install.html 下载地址:http://www.cnplugins.com/down/p ...
- window 启用 windows 自动登录
启用 windows 自动登录 方案一: 1.运行命令:control userpasswords2 2.取掉复选框的钩: 方案二:(方案一无效的时候使用) 微软官网地址:https://suppor ...