그냥 조합문제이다
P를 입력받을 때
P에 해당하는 문자열은
포함관계이거나 포함관계가 아니다
나는 문자열의 앞부분부터 비교해가면서
포함관계인지 아닌지 처리해주었다.
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int T;cin>>T;int idx = 1;
while(T){
T--;
int N,P;cin>>N>>P;
vector<string> v;
for(int i=0;i<P;i++){
string a;cin>>a;
v.push_back(a);
}
long long ans = pow(2,N);
sort(v.begin(),v.end());
for(int i=0;i<v.size();i++){
string now = v[i];
bool flag = true;
for(int t=0;t<i;t++){
string c = v[t];
string temp = now;
temp = temp.substr(0,c.length());
if(c==temp){
flag = false;break;
}
}
if(flag){
ans -= pow(2,N-now.length());
}
}
cout<<"Case #"<<idx<<": "<<ans<<"\n";
idx++;
}
}