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. android Menu 笔记

    菜单是应用中常见的用户组件.本文介绍如何在布局文件和代码中添加menu,submenu以及在代码中添加的方法. 参考链接 https://developer.android.com/guide/top ...

  2. 优矿众包对冲基金计划”优选策略---100w实盘资金管理权!!

    https://uqer.io/contest/ http://www.cnblogs.com/dunitian/p/4939369.html 优连

  3. 转载:【原译】Erlang常见注意事项(Efficiency Guide)

    转自:http://www.cnblogs.com/futuredo/archive/2012/10/17/2726416.html Common Caveats(常见注意事项) Erlang/OTP ...

  4. CentOS下screen 命令详解

    一.背景 系统管理员经常需要SSH 或者telent 远程登录到Linux 服务器,经常运行一些需要很长时间才能完成的任务,比如系统备份.ftp 传输等等.通常情况下我们都是为每一个这样的任务开一个远 ...

  5. 安装并配置ROS环境1

    ros学习之路(原创博文,转载请标明出处-周学伟http://www.cnblogs.com/zxouxuewei/) 一.ros核心教程    1.安装并配置ROS环境: 注意: 学习这节课之前请按 ...

  6. [Scikit-learn] Dynamic Bayesian Network - Kalman Filter

    看上去不错的网站:http://iacs-courses.seas.harvard.edu/courses/am207/blog/lecture-18.html SciPy Cookbook:http ...

  7. ios 在https情况下,使用webview加载url出错的解决方法 ios9 适配问题

    修改info.plist文件,添加App Transport Security Settings,然后在这个里面添加Allow Arbitrary Loads,改为yes 如下图:

  8. Windows 端口占用

    1.netstat -ano | findstr "80"( 80为提示被占用的端口): 2.tasklist | findstr "5584"(5584是从上 ...

  9. 【RF库Collections测试】Get From Dictionary

    Name:Get From DictionarySource:Collections <test library>Arguments:[ dictionary | key ]Returns ...

  10. 用命令行执行ROBOT FRAMEWORK用例

    转自:http://www.51testing.com/html/86/n-1430786.html 除了在ride中执行用例,我们也可以通过命令行的形式执行用例. 1.执行一整个项目 pybot+项 ...