dp边界条件又错了,最开始没加dp[0][0] = 1。以后可以把dp想成一个二维数组,从第一行推到第n行。那么推导第一行的时候就需要第0行。这么想就不容易错了。
坑点:dp边界条件
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long long lint;
const lint maxn = 30;
const lint mod = 1000000007;
lint v[maxn],c[maxn];
vector<lint> object,query;
void init(){
query.clear();
object.clear();
}
void solve( lint n ){
for( lint i = 1;i <= n;i++ ){
lint vv = (1<< (c[i] - 1));
for( ;vv >=1;vv >>= 1 ){
object.push_back( (v[i]*vv)%mod );
}
}
}
const lint maxs = 10001;
lint dp[450][maxs];
void solve2( lint s ){
for( lint i = 0;i < object.size();i++ ){
dp[i][0] = 1;
for( lint j = 1;j <= s;j++ ){
dp[i][j] = 0;
if(i )
dp[i][j] = (dp[i][j]+dp[i-1][j])%mod;
if( j - object[i] >= 0 )
dp[i][j] = (dp[i][j] + dp[i][ j - object[i] ])%mod;
}
}
}
int main(){
lint T,n,q;
scanf("%lld",&T);
while( T-- ){
init();
scanf("%lld%lld",&n,&q);
for( lint i = 1;i <= n;i++ ){
scanf("%lld%lld",&v[i],&c[i]);
}
lint mm = 0;
for( lint x,i = 1;i <= q;i++ ){
scanf("%lld",&x);
mm = max( mm,x );
query.push_back( x );
}
solve(n);
solve2(mm);
for( lint i = 0;i < query.size();i++ ){
printf("%lld\n", dp[ object.size()-1 ][ query[i] ] );
}
}
return 0;
}