Codeforces Round #329 (Div. 2) A.2Char 暴力

A. 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 nlines, 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

4abbcaccaaabbb

output

9

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‘}.

题意:给你n个字符串只含小写字母,现在挑出任意个串,个数最大,但是所挑的串只含两种字母

题解:预处理出每个串的字母种类

在暴力枚举两种串就好了

///1085422276
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
inline ll read()
{
    ll x=0,f=1;
    char ch=getchar();
    while(ch<‘0‘||ch>‘9‘)
    {
        if(ch==‘-‘)f=-1;
        ch=getchar();
    }
    while(ch>=‘0‘&&ch<=‘9‘)
    {
        x=x*10+ch-‘0‘;
        ch=getchar();
    }
    return x*f;
}
//****************************************
#define maxn 1000000+5
#define mod 1000000007
vector<int >G[500];
int H[200];
int aa[500],n;
char a[101][1001];
int main(){
   mem(H);
   scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%s",a[i]);
        int flag=0;
        for(int j=0;j<strlen(a[i]);j++){
            H[a[i][j]]++;
            flag++;G[i].push_back(a[i][j]);
        }
        aa[i]=flag;
    }
    int sum;
    int ans=0;
     for(int i=‘a‘;i<=‘z‘;i++){
        for(int j=‘a‘;j<=‘z‘;j++){
            if(i==j)continue;
            sum=0;
            for(int k=1;k<=n;k++){
                        bool can=1;
                     for(int g=0;g<G[k].size();g++){
                        if(G[k][g]!=i&&G[k][g]!=j)can=0;
                     }
                if(can)sum+=strlen(a[k]);
            }
            ans=max(sum,ans);
        }
    }cout<<ans<<endl;
  return 0;
}

代码

时间: 2024-10-05 17:28:49

Codeforces Round #329 (Div. 2) A.2Char 暴力的相关文章

随笔—邀请赛前练— Codeforces Round #329 (Div. 2) 2Char

题意:给你多个字符串,只保留2及2个以内的字符,丢弃多余的字符串,问你最后留下的字符串最长能有多长? 思路: 1. 对每个字符串处理出  process[fir][sec]  只包含fir字符和sec字符 当前的最大长度.当然,超过2个字符的字符串自动跳过. 2. 注意合并 process[fir][sec].process[sec][fir].process[fir][0].process[sec][0] 3. 合并的过程还要注意特殊情况 process[fir][0] + process[s

Codeforces Round #329 (Div. 2)B. Anton and Lines 贪心

B. Anton and Lines The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = ki·x + bi. It was necessar

Codeforces Round #266 (Div. 2)B(暴力枚举)

很简单的暴力枚举,却卡了我那么长时间,可见我的基本功不够扎实. 两个数相乘等于一个数6*n,那么我枚举其中一个乘数就行了,而且枚举到sqrt(6*n)就行了,这个是暴力法解题中很常用的性质. 这道题找出a和b中最小的那个,然后开始枚举,一直枚举到sqrt(6*n)的向上取整.这样所有可能是答案的情况都有啦.再干别的都是重复的或者肯定不是最小面积的. #include<iostream> #include<cstdio> #include<cstdlib> #includ

Codeforces Round #415 (Div. 2)(A,暴力,B,贪心,排序)

A. Straight «A» time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year.

Codeforces Round #224 (Div. 2) D 暴力搜索加记忆化

题意读了半年,英语太渣,题意是摆两个棋子在棋盘上作为起点,但是起点不能在#上,然后按照图的指示开始走, < 左 > 右 ^上 v下,走的时候只能按照图的指示走,如果前方是 #的话,可以走进去,但是 走进去之后便不能再走了,走的途中两个棋子不能相碰,但是最终都走到同一个#里是没事的,并且若是能走 无限步的话 输出 -1, 例如  > < 这样左右左右的走就能无限走,然后问你 两个棋子走的最大步数的和 一开始被输出-1给困住了,因为除了 .> <这样以外  还可以刚好形成一

Codeforces Round #422 (Div. 2) A. I&#39;m bored with life 暴力

A. I'm bored with life Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the

Codeforces Round #359 (Div. 2) C. Robbers&#39; watch (暴力DFS)

题目链接:http://codeforces.com/problemset/problem/686/C 给你n和m,问你有多少对(a, b) 满足0<=a <n 且 0 <=b < m 且a的7进制和n-1的7进制位数相同 且b的7进制和m-1的7进制位数相同,还有a和b的7进制上的每位上的数各不相同. 看懂题目,就很简单了,先判断a和b的7进制位数是否超过7,不超过的话就dfs暴力枚举计算就可以了. 1 //#pragma comment(linker, "/STACK

数学/找规律/暴力 Codeforces Round #306 (Div. 2) C. Divisibility by Eight

题目传送门 1 /* 2 数学/暴力:只要一个数的最后三位能被8整除,那么它就是答案:用到sprintf把数字转移成字符读入 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #include <cstring> 7 #include <iostream> 8 #include <cmath> 9 #include <vector> 10 using namespace std; 11

暴力 Codeforces Round #305 (Div. 2) B. Mike and Fun

题目传送门 1 /* 2 暴力:每次更新该行的num[],然后暴力找出最优解就可以了:) 3 */ 4 #include <cstdio> 5 #include <cstring> 6 #include <iostream> 7 #include <algorithm> 8 #include <string> 9 using namespace std; 10 11 const int MAXN = 5e2 + 10; 12 const int