#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
string s[30];
int n;
bool c[30];
int ans=0;
int main(){
cin>>n;
for(int i = 1; i<=n; i++) cin>>s[i];
for(int i = 0; i<(1<<n); i++){
memset(c,0,sizeof c);
string t;
for(int j = 1; j<=n; j++){
if(i>>(j-1)&1){
t+=s[j];
}
}
int cnt=0;
for(auto ch:t){
if(!c[ch-'a'+1]) cnt++,c[ch-'a'+1]=1;
}
if(cnt==26){
ans++;
}
}
cout<<ans;
return 0;
}
显然是 O(2n×n) 的,数据范围是 n≤25.
如果不行,怎么优化?