ACM-ICPC 2018 焦作赛区网络预赛 K Transport Ship (多重背包)
https://nanti.jisuanke.com/t/31720
题意
t组样例,n种船只,q个询问,接下来n行给你每种船只的信息:v[i]表示这个船只的载重,c[i]表示这种船只有2^(c[i]−1)只。
对于每个询问,求用这些船装s的货物的方案数有多少,用到的船必须装满。
分析
一眼就是背包类的题,多重背包求方案数,将数量为m的物体分为log2(m)种物体,然后做01背包。在这里只需改改多重背包模板的转移式子就好。
背包九讲小总结:https://www.cnblogs.com/fht-litost/p/9204147.html
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e4+;
const int mod = 1e9 + ; ll F[maxn];
int V=;
void ZeroOnePack(int C){
for(int v = V; v>=C ; v--)
F[v] = (F[v]+F[v-C])%mod;
}
void CompletePack(int C){
for(int v = C; v<=V ; v++)
F[v] = (F[v]+F[v-C])%mod;
}
void MultiplePack(int C,int M){
if( C*M >= V ){
CompletePack(C);
return;
}
int k = ;
while( k < M ){
ZeroOnePack(k*C);
M = M - k;
k <<= ;
}
ZeroOnePack(M*C);
} int main(){
int t;
scanf("%d",&t);
while(t--){
int n,q,s,v,c;
scanf("%d%d",&n,&q);
memset(F,,sizeof(F));
F[]=;
for(int i=;i<=n;i++){
scanf("%d%d",&v,&c);
c=(<<c)-;
MultiplePack(v,c);
}
while(q--){
scanf("%d",&s);
printf("%lld\n",F[s]);
}
}
return ;
}
ACM-ICPC 2018 焦作赛区网络预赛 K Transport Ship (多重背包)的更多相关文章
- ACM-ICPC 2018 焦作赛区网络预赛 K. Transport Ship(DP)
题目链接:https://nanti.jisuanke.com/t/31720 题意:有n种飞船,每种飞船有(1 << c)- 1 艘,容量为 k[i] ,q 次询问,每次询问选若干艘飞 ...
- ACM-ICPC 2018 焦作赛区网络预赛 K题 Transport Ship
There are NN different kinds of transport ships on the port. The i^{th}ith kind of ship can carry th ...
- ACM-ICPC 2018 焦作赛区网络预赛- L:Poor God Water(BM模板/矩阵快速幂)
God Water likes to eat meat, fish and chocolate very much, but unfortunately, the doctor tells him t ...
- ACM-ICPC 2018 焦作赛区网络预赛
这场打得还是比较爽的,但是队友差一点就再过一题,还是难受啊. 每天都有新的难过 A. Magic Mirror Jessie has a magic mirror. Every morning she ...
- ACM-ICPC 2018 焦作赛区网络预赛J题 Participate in E-sports
Jessie and Justin want to participate in e-sports. E-sports contain many games, but they don't know ...
- ACM-ICPC 2018 焦作赛区网络预赛 L 题 Poor God Water
God Water likes to eat meat, fish and chocolate very much, but unfortunately, the doctor tells him t ...
- ACM-ICPC 2018 焦作赛区网络预赛 B题 Mathematical Curse
A prince of the Science Continent was imprisoned in a castle because of his contempt for mathematics ...
- ACM-ICPC 2018 焦作赛区网络预赛- G:Give Candies(费马小定理,快速幂)
There are N children in kindergarten. Miss Li bought them NNN candies. To make the process more inte ...
- ACM-ICPC 2018 焦作赛区网络预赛 I题 Save the Room
Bob is a sorcerer. He lives in a cuboid room which has a length of AA, a width of BB and a height of ...
随机推荐
- 【BZOJ2333】【SCOI2011】棘手的操作 treap合并
题目大意 有\(n\)个节点,标号从1到\(n\),这\(n\)个节点一开始相互不连通.第\(i\)个节点的初始权值为\(a_i\),接下来有如下一些操作: \(U~x~y\):加一条边,连接第\(x ...
- MT【260】单调函数
设$f(x)$是定义在$(0,+\infty)$上的单调函数,且对定义域内的任意实数$x$,都有$f(f(x)-\log_2 x)=3$, 求$f(x)-f^{'}(x)=2$的解所在的区间.____ ...
- 【HDU 6036】Division Game (NTT+数学)
多校1 1004 HDU-6036 Division Game 题意 有k堆石头(0~k-1),每堆n个.\(n=\prod_{i=0}^{m}p_i^{e_i}\).\(0\le m,k \le 1 ...
- [复习]莫比乌斯反演,杜教筛,min_25筛
[复习]莫比乌斯反演,杜教筛,min_25筛 莫比乌斯反演 做题的时候的常用形式: \[\begin{aligned}g(n)&=\sum_{n|d}f(d)\\f(n)&=\sum_ ...
- rt-thread中软件定时器组件超时界限的一点理解
@2019-01-15 [小记] 对 rt-thread 中的软件定时器组件中超时界限的一点理解 rt_thread_timer_entry(void *parameter)函数中if ((next_ ...
- nginx php-fpm conf文件编写
coco.conf ##upstream upstream php_coco_backend{ server 127.0.0.1:8019; } server { listen 80; server_ ...
- CentOS6 部署 Tomcat
安装java软件 yum install java-1.8.0* -y 设置开机自启,在/etc/init.d/下新建 tomcat 写入以下内容: #!/bin/bash # /etc/rc.d/i ...
- 20165223 实验一 Java开发环境的熟悉
目录 一.实验报告封面 二.实验内容 (一)命令行下的JAVA程序开发 (二)IDEA中的JAVA程序开发 (三)自主练习 三.实验总结 四.PSP时间 一.实验报告封面 北京电子科技学院(BESTI ...
- POJ--3614 Sunscreen(贪心)
题目 3614 Sunscreen 2500*2500直接排序暴力贪心 #include<iostream> #include<cstring> #include<alg ...
- 【POJ2230】Watchcow
题目大意:给定一个 N 个点,M 条边的无向图,要求不重复地经过每条边两次,并且从 1 号节点出发最后回到 1 号节点,求一条路径. 题解:不重复地经过两次这个操作很容易地通过无向图的建边方式来实现, ...