ACM-ICPC2018焦作网络赛 Transport Ship(二进制背包+方案数)
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
题目来源
#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(二进制背包+方案数)的更多相关文章
- 焦作网络赛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 ...
- ACM-ICPC 2018 焦作网络赛
题目顺序:A F G H I K L 做题链接 A. Magic Mirror 题意:判断 给出的 字符串 是否等于"jessie",需要判断大小写 题解:1.用stl库 tolo ...
- 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焦作网络赛 K】Transport Ship(多重背包二进制优化)
There are N different kinds of transport ships on the port. The ith kind of ship can carry the weigh ...
- 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] ...
- 焦作网络赛B-Mathematical Curse【dp】
A prince of the Science Continent was imprisoned in a castle because of his contempt for mathematics ...
- 焦作网络赛E-JiuYuanWantstoEat【树链剖分】【线段树】
You ye Jiu yuan is the daughter of the Great GOD Emancipator. And when she becomes an adult, she wil ...
- 焦作网络赛L-Poor God Water【矩阵快速幂】
God Water likes to eat meat, fish and chocolate very much, but unfortunately, the doctor tells him t ...
随机推荐
- 【模板】P3806点分治1
[模板]P3806 [模板]点分治1 很好的一道模板题,很无脑经典. 讲讲淀粉质吧,很营养,实际上,点分治是树上的分治算法.根据树的特性,树上两点的路径只有一下两种情况: 路径经过根\((*)\) 路 ...
- BTC、BCH和BSV三者到底有什么区别?
比特币发展到今天已经有10个年头了,在这十年的发展中,比特币一共经历了两次重要的分裂,现在变成了三种货币,第一种是目前继承了比特币绝大多数遗产的BTC:第二种是BCH:第三种是BSV.那这三种货币到底 ...
- java多线程系列 JUC锁01 框架
转载 http://www.cnblogs.com/skywang12345/p/3496098.html 参考 https://www.cnblogs.com/leesf456/p/5453091. ...
- Object.create用法
用法: Object.create(object, [,propertiesObject]) 创建一个新对象,继承object的属性,可添加propertiesObject添加属性,并对属性作出详细解 ...
- matlab给图片插入说明文字
text(cluster().center(),cluster().center(),num2str(),'color','k') 格式是text(x,y,'说明文字') x,y代表位置
- ThinkPHP基础(1)
多层MVC模式 M:Model 数据模型层,负责数据操作 V:View 视图层,负责显示视图 C:Controller 控制器,实现业务逻辑 控制器访问及路由解析 通过url地址get参数找到指定的控 ...
- PHP的Calling Scope(::调用非静态方法)
今天在群里发现有人说,PHP可以用::调用非静态方法,一致没这么试过,发现了鸟哥的blog写了这个问题的具体解释,就搬过来: 这个问题乍看, 确实很容易让人迷惑, 但实际上, 造成这样的误解的根本原因 ...
- db2move 数据导出整理
db2move <database-name> <action> [<option> <value>] 命令解释:1).database-name, ...
- CC通信软件list
bozokgh0stnanocoredarkcometponydarkcometadwindadzokaecomblacknixbluebananacorigaratdarkcometDRAThuig ...
- SENet(Squeeze-and-Excitation Networks)算法笔记---通过学习的方式来自动获取到每个特征通道的重要程度,然后依照这个重要程度去提升有用的特征并抑制对当前任务用处不大的特征
Momenta详解ImageNet 2017夺冠架构SENet 转自机器之心专栏 作者:胡杰 本届 CVPR 2017大会上出现了很多值得关注的精彩论文,国内自动驾驶创业公司 Momenta 联合机器 ...