bitset使用样例
bitset可将01字符串转换为01数组,快速进行位运算等操作
bitset<int>(string) //将01字符串转换为01数组
例题
https://ac.nowcoder.com/acm/contest/92972/D
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define lowbit(x) (x&-x)
using namespace std;
const double pi=acos(-1);
void solve(){
int n,m;cin>>n>>m;
vector<int> ans(n);
vector<bitset<20>> pe(n);
for(int i=0;i<n;i++){
string s;cin>>s;
pe[i]=bitset<20>(s);
}
int q;cin>>q;
vector<bitset<20>> md(q);
for(int i=0;i<q;i++){
string y;cin>>y;
md[i]=bitset<20>(y);
}
for(int i=0;i<n;i++){
int mn=1e14;
bool ok=0;
for(int bt=0;bt<(1<<q);bt++){
bitset<20> t;
int cnt=0;
for(int j=0;j<q;j++){
if(bt & (1<<j)){
t |= md[j];
cnt++;
}
}
if((t|pe[i])==t){
mn=min(mn,cnt);
ok=1;
}
}
if(ok) cout<<mn<<endl;
else cout<<-1<<endl;
}
}
signed main(){
ios::sync_with_stdio(false); cin.tie(nullptr);
int t=1;
//cin>>t;
while(t--) solve();
return 0;
}