ACM-ICPC 2018 焦作赛区网络预赛-K

  • Post author:
  • Post category:其他


There are NN different kinds of transport ships on the port. The i^{th}ith kind of ship can carry the weight of V[i]V[i] and the number of the i^{th}ith kind of ship is 2^{C[i]} – 12C[i]−1. How many different schemes there are if you want to use these ships to transport cargo with a total weight of SS?

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 \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 \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 lines, each line contains two integers: V[i](1 \le V[i] \le 20), C[i](1 \le C[i] \le 20)V[i](1≤V[i]≤20),C[i](1≤C[i]≤20), representing the weight the i^{th}ith kind of ship can carry, and the number of the i^{th}ith kind of ship is 2^{C[i]} – 12C[i]−1.

For the next QQ lines, each line contains a single integer: 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.

样例输入复制

1
1 2
2 1
1
2

样例输出复制

0
1

题意:有n种船每种船数量为2^c[i]-1 有q个询问每一次一个s问组成s有多少种方式;

题解:因为有2^c[i]-1数量的船所以可以分别组成的种类有v[i],v[i]*2….v[i]*2^(c[i]-1);这样就转化成了01背包问题


#include<cstring>
#include<cstdio>
#include<iostream>
#include<string>
#include<queue>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<functional>
using namespace std;
#define clr(a,b) memset(a,b,sizeof(a))
#define lowbit(x) x&-x
#define rep(a,b,c) for(ll a=b;a<c;a++)
#define dec(a,b,c) for(int a=b;a>c;a--)
#define eb(x) emplace_back(x)
#define pb(x) push_back(x)
#define ps(x) push(x)
#define MAX_N 10000+5
#define MAX_M 100
typedef long long ll;
typedef unsigned long long ull;
typedef priority_queue<ll,vector<ll>,greater<ll> >pqg;
const ll maxn=1000+5;
const ll inf=1e7;
ll mod=1e9+7;
int  n,q,v[25],c[25];
ll res[MAX_N];
void solve()
{
    clr(res,0);
    res[0]=1;
    for(int i=0; i<n; i++)
    {
       for(int j=0;j<c[i];j++)
       {
           int w=v[i]<<j;
           for(int s=10001;s>=w;s--)
           {
              res[s]+=res[s-w];
              res[s]%=mod;
           }
       }
    }
    return ;
}
int main()
{
#ifndef ONLINE_JUDGE
    // freopen("data.txt","r",stdin);
#endif
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&n,&q);
        for(int i=0; i<n; i++)
        {
            scanf("%d%d",&v[i],&c[i]);
        }
        solve();
        while(q--)
        {
            int s;
            scanf("%d",&s);
            printf("%d\n",res[s]);
        }
    }
    return 0;
}



版权声明:本文为Dog_dream原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。