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 ...
 
随机推荐
- HttpModule与HttpHandler详解(转)
			
ASP.NET对请求处理的过程:当请求一个*.aspx文件的时候,这个请求会被inetinfo.exe进程截获,它判断文件的后缀(aspx)之后,将这个请求转交给 ASPNET_ISAPI.dll,A ...
 - Swift 学习笔记 (继承)
			
一个类可以从另一个类继承方法.属性和其他的特性.当一个类从另一个类继承的时候,继承的类就是所谓的子类,而这个类继承的类被称为父类. 在 Swift 中类可以调用和访问属于它们父类的方法.属性和下标脚本 ...
 - (转)javascript中call()、apply()、bind()的用法
			
其实是一个很简单的东西,认真看十分钟就从一脸懵B 到完全 理解! 先看明白下面: 例1 obj.objAge; //17 obj.myFun() //小张年龄undefined 例2 shows( ...
 - Java基础之I/O流
			
一.数据流的基本概念 数据流是一串连续不断的数据的集合,就象水管里的水流,在水管的一端一点一点地供水,而在水管的另一端看到的是一股连续不断的水流.数据写入程序可以是一段.一段地向数据流管道中写入数据, ...
 - Pandas一些小技巧
			
Pandas有一些不频繁使用容易忘记的小技巧 1.将不同Dataframe写在一个Excel的不同Sheet,或添加到已有Excel的不同Sheet(同名Sheet会覆盖) from pandas i ...
 - 【python】python版本升级,从2.6.6升级到2.7.13
			
centos6.5系统自带了2.6.6版本的python,有时候为了项目上的需要,需要将python版本升级到2.7.13,下面介绍了如何进行升级. 说明:python从2.6升级到2.7会引发很多问 ...
 - sys添加路径
			
暂时更改sys.path sys.path.append()
 - vue.use解析
			
vue.use源码: Vue.use = function (plugin) { /*判断插件是否已引入*/ if (plugin.installed) { return } //倒序为一个数组[] ...
 - Uncaught TypeError: Illegal invocation解决
			
jquery中报了这个错,仔细一看,有个使用ajax的地方,其中有个参数是从页面某个文本框获取的,本应该 $('#id').value ,被我写成了 $('id') .所以报错,目前已解决.
 - CentOS Wifi Connection
			
方法一: http://wiki.centos.org/HowTos/Laptops/WpaSupplicant http://www.cnblogs.com/tanghuimin0713/p/343 ...