There are
NN
N different kinds of transport ships on the port. The
ithi^{th}
i
th
kind of ship can carry the weight of
V[i]V[i]
V[i] and the number of the
ithi^{th}
i
th
kind of ship is
2C[i]−12^{C[i]} - 1
2
C[i]
−1. How many different schemes there are if you want to use these ships to transport cargo with a total weight of
SS
S?
It is required that each ship must be full-filled. Two schemes are considered to be the same if they use the same kinds of ships and the same number for each kind.
Input
The first line contains an integer
T(1≤T≤20)T(1 \le T \le 20)
T(1≤T≤20), which is the number of test cases.
For each test case:
The first line contains two integers:
N(1≤N≤20),Q(1≤Q≤10000)N(1 \le N \le 20), Q(1 \le Q \le 10000)
N(1≤N≤20),Q(1≤Q≤10000), representing the number of kinds of ships and the number of queries.
For the next
NN
N lines, each line contains two integers:
Vi,CiV[i](1 \le V[i] \le 20), C[i](1 \le C[i] \le 20)
Vi,Ci, representing the weight the
ithi^{th}
i
th
kind of ship can carry, and the number of the
ithi^{th}
i
th
kind of ship is
2C[i]−12^{C[i]} - 1
2
C[i]
−1.
For the next
QQ
Q lines, each line contains a single integer:
S(1≤S≤10000)S(1 \le S \le 10000)
S(1≤S≤10000), representing the queried weight.
Output
For each query, output one line containing a single integer which represents the number of schemes for arranging ships. Since the answer may be very large, output the answer modulo
10000000071000000007
1000000007.
样例输入
复制
1
1 2
2 1
1
2
样例输出
复制
0
1
多重背包记录一下方案数即可;
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
#include<cctype>
//#pragma GCC optimize("O3")
using namespace std;
#define maxn 200005
#define inf 0x3f3f3f3f
#define INF 0x7fffffff
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9 + 7;
#define Mod 20100403
#define sq(x) (x)*(x)
#define eps 1e-15
const int N = 2500005;
inline int rd() {
int x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
}
ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
int dp[maxn];
int n, q;
int v[maxn], c[maxn];
int main()
{
//ios::sync_with_stdio(false);
int t; t = rd();
while (t--) {
// n = rd(); q = rd();
scanf("%d%d", &n, &q);
ms(dp); dp[0] = 1;
for (int i = 1; i <= n; i++) {
// v[i] = rd();
// c[i] = rd();
scanf("%d%d", &v[i], &c[i]);
}
for (int i = 1; i <= n; i++) {
ll cur = 1;
for (int j = 1; j <= c[i]; j++) {
for (int k = 10000; k >= cur * v[i]; k--) {
dp[k] = (dp[k] + dp[k - cur * v[i]]) % mod;
}
cur <<= 1;
}
}
while (q--) {
int x; //x = rd();
scanf("%d", &x);
//cout << dp[x] << endl;
printf("%lld\n", dp[x]);
}
}
return 0;
}