https://ac.nowcoder.com/acm/contest/57361/I
分治,容斥原理
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 998244353;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll n;
cin>>n;
vector<string> a[405];
for(int i=1;i<=n;i++){
string s;
cin>>s;
a[s.size()].push_back(s);
}
ll ans=0;
for(int i=1;i<=400;i++){
int num=a[i].size();
if(i<=20){
for(int j=0;j<(1<<i);j++){
for(int k=0;k<num;k++){
int book=1;
for(int t=0;t<i;t++){
if(a[i][k][t]!='?'&&((j>>t)&1)!=a[i][k][t]-'0'){
book=0;
break;
}
}
if(book){
ans=(ans+1)%mod;
break;
}
}
}
}
else{
for(int j=1;j<(1<<num);j++){
ll cnt=1,cntj1=0;
for(int t=0;t<i;t++){
int book0=0,book1=0;
for(int k=0;k<num;k++){
if(((j>>k)&1)==1){
if(t==0) cntj1++;
if(a[i][k][t]=='0') book0=1;
if(a[i][k][t]=='1') book1=1;
}
}
if(book0&&book1){
cnt=0;
break;
}
if(book0==0&&book1==0){
cnt=cnt*2%mod;
}
}
if(cntj1%2){
ans=(ans+cnt)%mod;
//cout<<" + "<<ans<<endl;
}
else{
//cout<<" - "<<ans<<endl;
ans=(ans-cnt+mod)%mod;
}
}
}
}
cout<<ans;
}