Transport Ship

  • 25.78%
  • 1000ms
  • 65536K
 

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

题目来源

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

#include<bits/stdc++.h>
#define MAX 105
#define MOD 1000000007
using namespace std;
typedef long long ll; int v[MAX],c[MAX],a[];
int two[MAX];
ll dp[]; void init(){
two[]=;
for(int i=;i<=;i++){
two[i]=two[i-]*;
}
}
int main()
{
int t,n,q,V,i,j;
init();
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&q);
for(i=;i<=n;i++){
scanf("%d%d",&v[i],&c[i]);
c[i]=two[c[i]]-;
}
int cc=;
for(i=;i<=n;i++){
if(c[i]==) continue;
for(j=;j<=c[i];j<<=){
cc++;
a[cc]=j*v[i];
c[i]-=j;
}
if(c[i]==) continue;
cc++;
a[cc]=c[i]*v[i];
}
memset(dp,,sizeof(dp));
dp[]=;
for(i=;i<=cc;i++){
for(j=;j>=a[i];j--){
dp[j]+=dp[j-a[i]];
dp[j]%=MOD;
}
}
while(q--){
scanf("%d",&V);
printf("%lld\n",dp[V]%MOD);
}
}
return ;
}

最新文章

  1. Mybatis学习总结(一)——入门基础
  2. 使用SignalR实现即时通讯功能
  3. C++与C的指针的不同
  4. 使用keytool 生成证书
  5. 【OpenCV练习】简单显示图片的代码
  6. C Primer Plus_第四章_字符串和格式化输入输出_编程练习
  7. Point Grey FlyCapture 实例汇总
  8. python datetime时区转换
  9. Leetcode#172 Fractorial Trailing Zero
  10. Understanding page frames and pages
  11. windows下编译FreeSwitch
  12. 如何在Linux上编译c++文件
  13. poj2559 Largest Rectangle in a Histogram
  14. Python入门教程丨1300多行代码,让你轻松掌握基础知识点
  15. python 类继承与子类实例初始化
  16. javascript 进阶篇1 正则表达式,cookie管理,userData
  17. 爬虫笔记之JS检测浏览器开发者工具是否打开
  18. day5模块学习--sys模块
  19. ny488 素数环
  20. iOS水波纹效果

热门文章

  1. python循环导入的解决方案
  2. python仪表盘
  3. BFC和haslayout(IE6-7)(待总结。。。)
  4. UEditor上传文件的默认地址修改
  5. Spring Boot2.0之 yml的使用
  6. 分享知识-快乐自己:Hibernate中的 quert.list() 与 quert.iterate() 方法区别
  7. Android SDK和NDK
  8. ES6 generator 基础
  9. mysql之count
  10. Seq2SQL :使用强化学习通过自然语言生成SQL