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 焦作赛区网络预赛

题意:

有n种船 每种有2^c[i] - 1艘 每艘载重v[i]【必须完全装满】

现给出q次查询s 输出装载s的安排船的方案数

思路:

形如多重背包问题 用二进制的思想就行优化

dp[w]表示载重w时的方案数 他可由dp[w - v[i] * k]得到 其中k是系数

按照二进制的思想 每次k*=2 最多20次 并且判断和c[i]的关系

要注意因为是2^c[i] -1因此等号不能取

 // ConsoleApplication3.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
// //#include "pch.h"
#include <iostream>
#include<algorithm>
#include<stdio.h>
#include<set>
#include<cmath>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack> #define inf 0x3f3f3f3f using namespace std;
typedef long long LL; const int maxn = ;
const int maxs = ;
const LL mod = ;
int t, n, q, s;
int v[maxn], c[maxn];
LL dp[maxs]; int main()
{
cin >> t;
while (t--) {
scanf("%d%d", &n, &q);
for (int i = ; i < n; i++) {
scanf("%d%d", &v[i], &c[i]);
} memset(dp, , sizeof(dp));
dp[] = ; int k = ;
for (int j = ; j < ; j++) {
for (int i = ; i < n; i++) {
if (j >= c[i]) {
continue;
}
for (int w = maxs; w >= v[i] * k; w--) {
dp[w] += dp[w - k * v[i]];
dp[w] %= mod;
}
}
k *= ;
} while (q--) {
scanf("%d", &s);
printf("%lld\n", dp[s]);
}
}
}

焦作网络赛K-Transport Ship【dp】的更多相关文章

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

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

  2. 【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 ...

  3. ACM-ICPC 2018 焦作赛区网络预赛 K. Transport Ship(DP)

    题目链接:https://nanti.jisuanke.com/t/31720 题意:有n种飞船,每种飞船有(1 << c)- 1  艘,容量为 k[i] ,q 次询问,每次询问选若干艘飞 ...

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

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

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

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

  6. ACM-ICPC2018焦作网络赛 Mathematical Curse(dp)

    Mathematical Curse 22.25% 1000ms 65536K   A prince of the Science Continent was imprisoned in a cast ...

  7. ACM-ICPC 2018 焦作网络赛

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

  8. 2019-ACM-ICPC-沈阳区网络赛-K. Guanguan's Happy water-高斯消元+矩阵快速幂

    2019-ACM-ICPC-沈阳区网络赛-K. Guanguan's Happy water-高斯消元+矩阵快速幂 [Problem Description] 已知前\(2k\)个\(f(i)\),且 ...

  9. ACM-ICPC2018焦作网络赛 Transport Ship(二进制背包+方案数)

    Transport Ship 25.78% 1000ms 65536K   There are NN different kinds of transport ships on the port. T ...

随机推荐

  1. css -- outline轮廓

    outline:#00ff00 solid thick; 边框参数: 样式: none:默认,无轮廓 dotted:点状轮廓 dashed:虚线轮廓 solid:实现轮廓 double:双线轮廓,宽度 ...

  2. c++ vector init操作

    1) string str[n]={"hello", ...}; vector<string> strArray(str,str+n); 2) vector<st ...

  3. php把时间戳转换成英文格式

    <?php echo "时间格式1:".date("Y-m-d H:i:s ")."<br>";// 2010-06-12 ...

  4. 微信绑定用户服务端代码-根据code获取openId然后绑定用户

    目录结构: isa.qa.core.weixin.message.resp包和isa.qa.core.weixin.util包中为微信绑定的工具类,就不一一贴出代码,详见附件,下载地址: http:/ ...

  5. SQL-字符串连接聚合函数

    原文:http://blog.csdn.net/java85140031/article/details/6820699 问题: userId  role_name         role_id 1 ...

  6. MathTyp使用过程的几个问题

    最近毕业季,人们又开始了一波论文恐惧症了.每天都在不断地改来改去,格式还是不符合要求,头疼得要死.不仅如此,还发现公式是越改越乱,牵一发而全身,其它地方动一点,整个版面全都乱了,人都要抓狂了.知道你的 ...

  7. [转] 在图标库中,找到合适的图标 ico

    作者:xlrocket链接:https://www.zhihu.com/question/19857245/answer/241696797 在图标库中,找到合适的图标 或许,一些小伙伴会有收集图标的 ...

  8. webBrowser 模拟登录

    webBrowser1.Document.GetElementById("txtUsername").InnerText = "sdsy";//fill nam ...

  9. 服务端用例设计的思(tao)路!

    服务端的测试简单来说就是除了前端以外的的测试. 总的来说可以分为以下两类: 1.     WEB或者APP的提供业务逻辑的服务端接口测试 2.     数据库.缓存系统.中间件..jar包依赖.输入输 ...

  10. 查看网卡流量:sar

    sar(System Activity Reporter 系统活动情况报告)是目前 Linux 上最为全面的系统性能分析工具之一,可以从多方面对系统的活动进行报告,但我们一般用来监控网卡流量 [roo ...