【2018 ICPC焦作网络赛 K】Transport Ship(多重背包二进制优化)
There are N different kinds of transport ships on the port. The ith kind of ship can carry the weight of V[i]V[i] and the number of the ith kind of ship is 2c[i]-12^{C[i]} - 12. How many different schemes there are if you want to use these ships to transport cargo with a total weight of S?
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 N 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 ith kind of ship is 2c[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 10000000071000000007.
样例输入
1
1 2
2 1
1
2
样例输出
0
1
题意:
有N种船只,每种船只的载货量为V[i](以下代码用w[i]表示),每种船只的数量为2^c[i]-1。接下来有Q次询问,每次问有多少种载货方式可以填满容量S。
思路:
如果用裸的01背包的话时间复杂度是O(N*2^c[i]*10000),显然会超时,但是我们可以把每一种船合并,比如船只有2n-1艘的话,就拆成20+21+22+...+2n-1,1~2n-1之中的任意一个数都可以由拆分出来的数组成,将所有合并后的结果进行一次多重背包即可。
#include<bits/stdc++.h>
using namespace std;
const int MAX=1e4;
const int mod=1e9+;
typedef long long ll;
int w[],c[];
ll dp[MAX+];
int main()
{
int n,i,T,q,s,j,k;
ios::sync_with_stdio(false);
cin>>T;
while(T--)
{
cin>>n>>q;
for(i=;i<=n;i++)
cin>>w[i]>>c[i];
memset(dp,,sizeof(dp));
dp[]=;
for(i=;i<=n;i++) //共n种船
{
int t=;
for(j=;j<=c[i];j++)//每种船有2^c[i]-1只
{
for(k=MAX;k>=t*w[i];k--)
dp[k]=(dp[k]+dp[k-t*w[i]])%mod;
t<<=;
}
}
while(q--)
{
cin>>s;
cout<<dp[s]<<endl;
}
}
return ;
}
【2018 ICPC焦作网络赛 K】Transport Ship(多重背包二进制优化)的更多相关文章
- 2018 焦作网络赛 K Transport Ship ( 二进制优化 01 背包 )
题目链接 题意 : 给出若干个物品的数量和单个的重量.问你能不能刚好组成总重 S 分析 : 由于物品过多.想到二进制优化 其实这篇博客就是存个二进制优化的写法 关于二进制优化的详情.百度一下有更多资料 ...
- ACM-ICPC 2018 焦作赛区网络预赛 K Transport Ship (多重背包)
https://nanti.jisuanke.com/t/31720 题意 t组样例,n种船只,q个询问,接下来n行给你每种船只的信息:v[i]表示这个船只的载重,c[i]表示这种船只有2^(c[i] ...
- 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 由负数取模的性质 ...
- 【2018 ICPC焦作网络赛 G】Give Candies(费马小定理+快速幂取模)
There are N children in kindergarten. Miss Li bought them N candies. To make the process more intere ...
- 2018 ICPC 沈阳网络赛
2018 ICPC 沈阳网络赛 Call of Accepted 题目描述:求一个算式的最大值与最小值. solution 按普通算式计算方法做,只不过要同时记住最大值和最小值而已. Convex H ...
- 2018 ICPC 徐州网络赛
2018 ICPC 徐州网络赛 A. Hard to prepare 题目描述:\(n\)个数围成一个环,每个数是\(0\)~\(2^k-1\),相邻两个数的同或值不为零,问方案数. solution ...
- ACM-ICPC 2018 焦作赛区网络预赛 K. Transport Ship(DP)
题目链接:https://nanti.jisuanke.com/t/31720 题意:有n种飞船,每种飞船有(1 << c)- 1 艘,容量为 k[i] ,q 次询问,每次询问选若干艘飞 ...
- 2018 ICPC南京网络赛 L Magical Girl Haze 题解
大致题意: 给定一个n个点m条边的图,在可以把路径上至多k条边的权值变为0的情况下,求S到T的最短路. 数据规模: N≤100000,M≤200000,K≤10 建一个立体的图,有k层,每一层是一份原 ...
- 2018 ICPC青岛网络赛 B. Red Black Tree(倍增lca好题)
BaoBao has just found a rooted tree with n vertices and (n-1) weighted edges in his backyard. Among ...
随机推荐
- Html5的map在实际使用中遇到的问题及解决方案
前言:百度了一下html map,嗯嗯,介绍的挺详细的,如果是初学者,直接看他们的教程,挺好的,就不用我再多说了. 不过我发现一个问题,就是都是介绍map有什么属性怎么用的,这明显就是照搬文档自己再改 ...
- #单元测试#以karma+mocha+chai 为测试框架的Vue webpack项目(二)
学习对vue组件进行单元测试,先参照官网编写组件和测试脚本. 1.简单的组件 组件无依赖,无props 对于无需导入任何依赖,也没有props的,直接编写测试案例即可. /src/testSrc/si ...
- # putty的使用和保存配置
putty的使用和保存配置 之前使用的xshell5,但是突然之间需要我去注册,根本无法使用.在网上看到可以到官网申请家庭和学校版本,但是我的邮箱一直没有接收到邮件.于是我放弃xshell.就拿起了之 ...
- GCO团队合作
队名:GCO 队员: B20150304116谢冰媛 (组长) B20150304401王粲 B20150304115钟玺琛 B20150304226梁天海 ...
- CRM中间件里的发布-订阅者模式
从事务码SMW01里能观察到一个BDOC可能被发送往不止一个目的site去,比如下图所示的5个site都会收到该site,而高亮显示的SMOF_ERPSITE代表ERP系统QI3的client 504 ...
- One Order行项目里Item Category是怎么计算出来的
One Order的行项目里有个字段叫Item Category,我们在行项目里加入一个product后,就会自动带出Item Category来.这个值是怎么计算出来的? 检查CRMD_ORDERA ...
- Release模式下无法调试打印对象的解决方式
之前碰到在release模式下无法打印对象的问题,只能切换到debug模式下调试, xcode release 模式下, 会关掉断点读取变量的上下文环境,以提高运行速度, ⚠️ 记得调试完再改回去,防 ...
- luogu P4168 [Violet]蒲公英
嘟嘟嘟 分块经典题竟然是一道黑题…… 分块求区间众数的大体思想是对于询问区间[L, R],预处理出这中间的整块的众数,然后统计两边零散的数在[L, R]中出现的次数,最后取出现次数最多且最小的数. 因 ...
- Strtus2框架使用HttpServletResponse响应数据
-----------------------------------------------------------------------------------------jsp-------- ...
- 推荐一个zookeeper信息查看工具
zookeeper信息查看工具 下载地址:https://issues.apache.org/jira/secure/attachment/12436620/ZooInspector.zip 解压,打 ...