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张多米诺骨牌,每张牌有两个面,然后给你一个无向图,保证没有环和一个顶点多条边的情况存在.现 ...
随机推荐
- Android Fragment用法详解(2)--动态添加Fragment
在上一篇文章<Android Fragment用法详解(1)--静态使用Fragment>我们讲解了Fragment的最简单的用法.这次我们来说一说Fragment复杂一丢丢的用法.在代码 ...
- Http 与Https
一个Http请求 DNS域名解析 --> 发起TCP的三次握手 --> 建立TCP连接后发起http请求 --> 服务器响应http请求,浏览器得到html代码 --> 浏览器 ...
- php apc 安装
APC简介 APC(Alternative PHP Cache)是一个PHP缓存.它在内存中存储PHP页面并且减少了硬盘的I/O.这对于性能的提升十分明显.你甚至可以在CPU使用率下降50%的情况下提 ...
- tomcat8.0的下载安装配置
配置tomcat前要先配置JDK的环境变量 具体方法请点链接JDK环境变量配置 首先要 到官网下载tomcat tomcat官网 进入官网后 如图在左侧选择自己想要下载的版本,这里我以8.0版本为例 ...
- ZROI2018提高day3t1
传送门 分析 我们可以用贪心的思想.对于所有并没有指明关系的数一定是将小的放在前面.于是我们按顺序在每一个已经指明大小顺序的数前面插入所有比它小且没有指明关系的数.详见代码. 代码 #include& ...
- Git 之 协同开发
GitHub中多人协同开发和单人开发还是有点差别,协同开发一般有两种方式: 合作者,将其他用户添加到仓库合作者中之后,该用户就具有向当前仓库提交代码. 组织,创建一个组织,然后再该组织下可以创建多个项 ...
- c语言中会遇到的面试题
预处理器(Preprocessor) 1 . 用预处理指令#define 声明一个常数,用以表明1年中有多少秒(忽略闰年问题) #define SECONDS_PER_YEAR (60 ...
- 形式化验证工具(PAT)羊车门代码学习
首先介绍一下PAT工具,下图是PAT工具的图标 PAT工具全称是Process Analysis Toolkit,可以做一些简单的验证. 今天我们分析一下例子里面的Monty Hall Problem ...
- 函数的返回值是如何带出和接收的以及内存中的活动情况.RP
函数返回值时,要生成一个值的副本. 而用引用返回值时,不生成值的副本. 例如,下面的程序是有关引用返回的4种形式: //********************* //** ch9_6.cpp ** ...
- undefined reference to `clock_gettime
下面这个错误通常是因为链接选项里漏了-lrt,但有时发现即使加了-lrt仍出现这个问题,使用nm命令一直,会发现-lrt最终指向的文件没有包含任何symbol,这个时候,可以找相应的静态库版本libr ...