博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #329 (Div. 2) A. 2Char 字符串+暴力
阅读量:4113 次
发布时间:2019-05-25

本文共 2590 字,大约阅读时间需要 8 分钟。

A. 2Char
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Sample test(s)
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*26*100*10^3=10^8  因此可以暴力而不会超时,可以数据范围能暗示解题方法

#include 
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std; #define MM(a) memset(a,0,sizeof(a)) typedef long long LL; typedef unsigned long long ULL; const int maxn = 1e3+5; const int mod = 1000000007; const double eps = 1e-10; const int INF = 0x3f3f3f3f; LL gcd(LL a, LL b) { if(b == 0) return a; return gcd(b, a%b); } char a[105][1005]; int main() { int n; while(~scanf("%d",&n)) { int maxn=0; for(int i=1;i<=n;i++) scanf("%s",a[i]); for(int i=0;i<=25;i++) for(int j=0;j<=25;j++) //暴力枚举选择的两个字母 { if(j==i) continue; int num=0; for(int k=1;k<=n;k++) { bool flag=true; for(int h=0;h
maxn) maxn=num; } printf("%d\n",maxn); } return 0; }

转载地址:http://wvgsi.baihongyu.com/

你可能感兴趣的文章
手绘VS码绘(二):动态图绘制(码绘使用Processing)
查看>>
基于P5.js的“绘画系统”
查看>>
《达芬奇的人生密码》观后感
查看>>
论文翻译:《一个包容性设计的具体例子:聋人导向可访问性》
查看>>
基于“分形”编写的交互应用
查看>>
《融入动画技术的交互应用》主题博文推荐
查看>>
链睿和家乐福合作推出下一代零售业隐私保护技术
查看>>
Unifrax宣布新建SiFAB™生产线
查看>>
艾默生纪念谷轮™在空调和制冷领域的百年创新成就
查看>>
NEXO代币持有者获得20,428,359.89美元股息
查看>>
Piper Sandler为EverArc收购Perimeter Solutions提供咨询服务
查看>>
RMRK筹集600万美元,用于在Polkadot上建立先进的NFT系统标准
查看>>
JavaSE_day12 集合
查看>>
JavaSE_day14 集合中的Map集合_键值映射关系
查看>>
Day_15JavaSE 异常
查看>>
异常 Java学习Day_15
查看>>
JavaSE_day_03 方法
查看>>
day-03JavaSE_循环
查看>>
Mysql初始化的命令
查看>>
day_21_0817_Mysql
查看>>