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 ;
}

ACM-ICPC2018焦作网络赛 Transport Ship(二进制背包+方案数)的更多相关文章

  1. 焦作网络赛K-Transport Ship【dp】

    There are NN different kinds of transport ships on the port. The i^{th}ith kind of ship can carry th ...

  2. ACM-ICPC 2018 焦作网络赛

    题目顺序:A F G H I K L 做题链接 A. Magic Mirror 题意:判断 给出的 字符串 是否等于"jessie",需要判断大小写 题解:1.用stl库 tolo ...

  3. 2018 ICPC 焦作网络赛 E.Jiu Yuan Wants to Eat

    题意:四个操作,区间加,区间每个数乘,区间的数变成 2^64-1-x,求区间和. 题解:2^64-1-x=(2^64-1)-x 因为模数为2^64,-x%2^64=-1*x%2^64 由负数取模的性质 ...

  4. 【2018 ICPC焦作网络赛 K】Transport Ship(多重背包二进制优化)

    There are N different kinds of transport ships on the port. The ith kind of ship can carry the weigh ...

  5. 2018 焦作网络赛 K Transport Ship ( 二进制优化 01 背包 )

    题目链接 题意 : 给出若干个物品的数量和单个的重量.问你能不能刚好组成总重 S 分析 : 由于物品过多.想到二进制优化 其实这篇博客就是存个二进制优化的写法 关于二进制优化的详情.百度一下有更多资料 ...

  6. ACM-ICPC 2018 焦作赛区网络预赛 K Transport Ship (多重背包)

    https://nanti.jisuanke.com/t/31720 题意 t组样例,n种船只,q个询问,接下来n行给你每种船只的信息:v[i]表示这个船只的载重,c[i]表示这种船只有2^(c[i] ...

  7. 焦作网络赛B-Mathematical Curse【dp】

    A prince of the Science Continent was imprisoned in a castle because of his contempt for mathematics ...

  8. 焦作网络赛E-JiuYuanWantstoEat【树链剖分】【线段树】

    You ye Jiu yuan is the daughter of the Great GOD Emancipator. And when she becomes an adult, she wil ...

  9. 焦作网络赛L-Poor God Water【矩阵快速幂】

    God Water likes to eat meat, fish and chocolate very much, but unfortunately, the doctor tells him t ...

随机推荐

  1. android菜鸟学习笔记13----Android控件(二) 自定义控件简单示例

    有时候,可能觉得系统提供的控件太丑,就会需要自定义控件来实现自己想要的效果. 以下主要参考<第一行代码> 1.自定义一个标题栏: 系统自带的标题栏很丑,且没什么大的作用,所以我们之前会在o ...

  2. iOS视频直播用到的协议

    一 .流媒体 1 - 伪流媒体 1.1 扫盲:边下载边播放1.2 伪流媒体:视频不是实时播放的,先把视频放在数据库,再供客户端访问,比如:优酷,爱奇艺等 1.3 特点: 边下边存,文件会保存.遵守了 ...

  3. 如果这种方式导致程序明显变慢或者引起其他问题,我们要重新思考来通过 goroutines 和 channels 来解决问题

    https://github.com/Unknwon/the-way-to-go_ZH_CN/blob/master/eBook/09.3.md 9.3 锁和 sync 包 在一些复杂的程序中,通常通 ...

  4. mysql系列之2.mysql多实例

    使用场景 资金紧张; 并发访问不大; 门户网站; 实现 生产硬件配置: mem 32G / 双cpu 8核 / 磁盘6*600G sas 15k, 2-3个实例 安装组件 #yum install n ...

  5. zendstudio 13.0

    官网原版下载 http://downloads.zend.com/studio-eclipse/13.0.0/ZendStudio-13.0.0-win32.win32.x86.exe 破解补丁: 链 ...

  6. 一起来学linux:网络配置

    上网首先需要网卡的支持.在linux中默认的网卡为eth0, 第二张网卡为eth1.如果是用的无线网卡则是wlan0.这个可以通过ifconfig查看到.结果如下.其中lo代表本地端口.root@zh ...

  7. c语言学习的第11天 指针

    #include<stdio.h> int main(void) { int * p; int i=3; int j; p=&i; j=*p; printf("i=%d, ...

  8. 9.1 NOIP普及组试题精解(1)

    9-1 series1.c #include <stdio.h> int main() { float s=0.0,k; int n; printf("输入数字k(1~15):& ...

  9. 反向ssh

    参考 https://www.thegeekstuff.com/2013/11/reverse-ssh-tunnel/ https://www.howtoforge.com/reverse-ssh-t ...

  10. 【坑坑坑坑坑】fwrite没有把数据写到文件中???

    原文:https://blog.csdn.net/kuaidfkuai/article/details/45918025 <unix环境高级编程>中介绍标准IO: 标准IO流操作读写普通文 ...