abc249 problem c

https://atcoder.jp/contests/abc249/tasks/abc249_c

N只有15,而且不好写,应该想到用二进制枚举来写的。

#include<bits/stdc++.h>
#define int long long 
#define pb push_back
#define fi first
#define se second 
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define cy cout<<"YES"<<endl
#define cn cout<<"NO"<<endl
#define de(x) cout<<x<<"###"<<endl
using namespace std;
const long long inf=2e18;
typedef long long ll;
typedef pair<ll,ll>pii;
typedef vector<ll>vi;
const double eps=1e-8;
const int mod=1e9+7;
const int N=20;
string s[N];
void solve(){
    int n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++)cin>>s[i];
    int ans=0;
    for(int i=0;i<1<<n;i++){
        map<char,int>mp;
        for(int j=0;j<n;j++){
            if(i>>j&1){
                for(auto x:s[j])mp[x]++;
            }
        }
        int cnt=0;
        for(auto x:mp){
            if(x.se==k)cnt++;
        }
        ans=max(ans,cnt);
    }
    cout<<ans<<endl;
}    
signed main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif 
    ios::sync_with_stdio(false);
      cin.tie(0);
//    int t;
//    cin>>t;
//    while(t--){
        solve();
//    }
    return 0;
}        

 

posted @ 2022-08-17 23:02  Candyk8d9  阅读(34)  评论(0)    收藏  举报