ACM-ICPC 2018 焦作赛区网络预赛 Transport Ship(dp)

There are N different kinds of transport ships on the port. The ith kind of ship can carry the weight of V[i] and the number of the ith kind of ship is 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?

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), 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), 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≤V[i]≤20),C[i](1≤C[i]≤20), representing the weight the ith kind of ship can carry, and the number of the i^{th}ith kind of ship is 2^C[i]−1.

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

样例输入复制

1
1 2
2 1
1
2

样例输出复制

0
1

题目来源

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

题意:给你一个n,表示有几种不同的船只,每种船只的容量为v,数量为2^c-1。装货要把船只装满。

q吃询问,每次一个s,问在这n种船只下有多少种不同的装货方案数。

解析:第一感觉很像是背包。背包就是dp。dp[k]=(dp[k]+dp[k-2^j])

#include<bits/stdc++.h>
using namespace std;
 
#define e exp(1)
#define pi acos(-1)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define ll long long
#define ull unsigned long long
#define mem(a,b) memset(a,b,sizeof(a))
int gcd(int a,int b){return b?gcd(b,a%b):a;}

const int maxn=1e4+10;
ll dp[maxn];
int main()
{
	int T;scanf("%d",&T);
	while(T--)
	{
		mem(dp,0);
		dp[0]=1;
		int n,q;scanf("%d%d",&n,&q);
		for(int i=0; i<n; i++)
		{
			int v,c;scanf("%d%d",&v,&c);
			
			int cnt=1;
			for(int j=1; j<=c; j++)
			{
				for(int k=10000; k>=cnt*v; k--)
				{
					dp[k]=(dp[k]+dp[k-cnt*v])%mod;
				}
				cnt<<=1;
			}
		}
		int s;
		for(int i=0; i<q; i++)
		{
			scanf("%d",&s);
			printf("%lld\n",dp[s]);
		}
	}
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值