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 (多重背包)的更多相关文章

  1. ACM-ICPC 2018 焦作赛区网络预赛 K. Transport Ship(DP)

    题目链接:https://nanti.jisuanke.com/t/31720 题意:有n种飞船,每种飞船有(1 << c)- 1  艘,容量为 k[i] ,q 次询问,每次询问选若干艘飞 ...

  2. 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 ...

  3. 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 ...

  4. ACM-ICPC 2018 焦作赛区网络预赛

    这场打得还是比较爽的,但是队友差一点就再过一题,还是难受啊. 每天都有新的难过 A. Magic Mirror Jessie has a magic mirror. Every morning she ...

  5. 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 ...

  6. 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 ...

  7. ACM-ICPC 2018 焦作赛区网络预赛 B题 Mathematical Curse

    A prince of the Science Continent was imprisoned in a castle because of his contempt for mathematics ...

  8. ACM-ICPC 2018 焦作赛区网络预赛- G:Give Candies(费马小定理,快速幂)

    There are N children in kindergarten. Miss Li bought them NNN candies. To make the process more inte ...

  9. 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 ...

随机推荐

  1. project 2013 任务显示编号

    1. 方法 格式-->大纲数字勾起来即可 2.结果

  2. 【 HDU3294 】Girls' research (Manacher)

    BUPT2017 wintertraining(15) #5F HDU - 3294 题意 给定字母x,字符串变换一下: 'x'-1 -> 'z', 'x'->'a', 'x'+1-> ...

  3. 【CF997E】Good Subsegments (线段树+单调栈)

    Description 原题链接 给你一个长度为\(n\)的排列\(~P\),定义一段子区间是好的,当且仅当这个子区间内的值构成了连续的一段.例如对于排列\(\{1,3,2 \}\),\([1, 1] ...

  4. github上的面试库

    https://yuchengkai.cn/docs/zh/frontend/#%E5%86%85%E7%BD%AE%E7%B1%BB%E5%9E%8B https://github.com/taiz ...

  5. nginx日志文件的定时切割与归纳

    应用环境:生产环境中的Nginx服务器,由于访问日志文件增长速度非常快,日志太大会严重影响服务器效率.同时,为了 方便对日志进行分析计算,须要对日志文件进行定时切割.定时切割的方式有按月切割.按天切割 ...

  6. Vue+Django2.0 restframework打造前后端分离的生鲜电商项目(1)

    1.开发环境配置 Windows7 64位旗舰版 python3.6 node.js mysql navicat pycharm webstorm或vscode 2.项目初始化 新版的pycharm很 ...

  7. increment/decrement/dereference操作符

    标题以上分别对于++/--/* #include <iostream> #include <cstddef> using namespace std; class INT { ...

  8. eclipse+pyDev

    感觉python脚本语言在linux下挺有用的,想入门学习一下 新手入门个人习惯找个好点的IDE帮助完成工作,试了好多,如pycharm,sublime text自己打造 后来发现全扯淡,一点不符合自 ...

  9. AOP和IOC

    AOP切面编程,作用:事务,日志,统一调用,统一实现,拦截,分发: 切点:告诉编译器切面作用于哪个package中的class IOC:控制反转,相对于new 对象来说的,依赖注入:AuthorWar ...

  10. 简单贪心) Repair the Wall hdu2124

    Repair the Wall http://acm.hdu.edu.cn/showproblem.php?pid=2124 Time Limit: 5000/1000 MS (Java/Others ...