先看题面
Problem Statement
Takahashi is standing at the coordinate 0 on a number line.
He will now perform N jumps. In the i-th jump (1≤i≤N), he moves ai or bi in the positive direction.
Is it possible for him to be at the coordinate X after N jumps?
Constraints
1≤N≤100
1≤ai<bi≤100(1≤i≤N)
1≤X≤10000
All values in input are integers.
大意就是高桥站在数轴上的坐标0处。
他将进行N次跳跃。在第i次跳跃(1≤i≤N)时,ai或bi向正方向移动。
在N次跳跃之后他是否可能在坐标X处?
看到这很多人会想到dp
但不用dp也是可以的
可能更简单一些???
用两个动态数组存ai,bi
再用bitset来当bool(可以省很多空间,详细可以去看一下这篇博客)
bitset是一种类似数组的结构,它的每一个元素只能是0或1,每个元素仅用1bit空间。
再判断v = (v << a[i]) | (v << b[i])这个式子就可以了
代码
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back