stOO
by thomas_zjl @ 2020-05-24 20:00:38
~~那些说bitset常数小的给我爪巴~~
by Malody @ 2020-05-24 20:00:45
同时谴责出题人,我的代码二进制没拆完也A了
by Malody @ 2020-05-24 20:05:00
@[我∈蒟蒻](/user/334548) ??
by 1saunoya @ 2020-05-24 20:05:54
怎么写的?
by 1saunoya @ 2020-05-24 20:06:04
@[Isaunoya](/user/96580)
by Malody @ 2020-05-24 20:06:24
```cpp
#include<bits/stdc++.h>
using namespace std;
//bitset<500010>f;
bool f[500010];
template<typename T>void read(T &cn)
{
char c;int sig = 1;
while(!isdigit(c = getchar())) if(c == '-') sig = -1; cn = c-48;
while(isdigit(c = getchar())) cn = cn*10+c-48; cn*=sig;
}
int main()
{
//freopen("watch.in","r",stdin);
//freopen("watch.out","w",stdout);
f[0]=1;
int n,m;
read(n);
read(m);
for(register int i=1;i<=n;++i)
{
int k,a;
read(k);
read(a);
int t=1;
int tt=500005-t*k;
while(a>=t)
{
for(register int j=tt;j>=0;--j)
if(f[j])
f[j+t*k]=1;
a-=t;
t<<=1;
}
/*if(a)
{
for(register int j=500005-a*k;j>=0;--j)
if(f[j])
f[j+a*k]=1;
}*/
}
for(register int i=1;i<=m;++i)
{
int t;
read(t);
if(f[t])
puts("Yes");
else
puts("No");
}
return 0;
}
by Malody @ 2020-05-24 20:06:32
@[Isaunoya](/user/96580) 剩下的a我没管
by Malody @ 2020-05-24 20:06:50
@[我∈蒟蒻](/user/334548) 这个写法不对吧?
by 1saunoya @ 2020-05-24 20:07:48
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m;
bitset <500005> qwq;
signed main() {
cin >> n >> m;
qwq[0] = true;
for(int i = 1; i <= n; i++) {
vector <int> v;
v.clear();
int k, a;
cin >> k >> a;
for(int j = 0; j < 20; j++)
if(a >= (1 << j)) {
v.push_back((1 << j) * k);
a -= 1 << j;
} else break;
if(a) v.push_back(a * k);
for(int j = 0; j < (int)v.size(); j++)
qwq |= qwq << v[j];
}
while(m--) {
int x;
cin >> x;
if(qwq[x])
cout << "Yes" << '\n';
else
cout << "No" << '\n';
}
return 0;
}
```
by 1saunoya @ 2020-05-24 20:08:18