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 ...
随机推荐
- CODEFORCES掉RATING记 #4
比赛:Codeforces Round #427 (Div. 2) 时间:2017.7.31晚 开场发现有6道题,都是水题(可能我只会做水题) A:比较\(2t_1+sv_1\)与\(2t_2+sv_ ...
- python学习日记(匿名函数)
匿名函数 简介 匿名函数:为了解决那些功能很简单的需求而设计的一句话函数. python 使用 lambda 来创建匿名函数. 所谓匿名,意即不再使用 def 语句这样标准的形式定义一个函数. lam ...
- rt-thread中软件定时器组件超时界限的一点理解
@2019-01-15 [小记] 对 rt-thread 中的软件定时器组件中超时界限的一点理解 rt_thread_timer_entry(void *parameter)函数中if ((next_ ...
- sql 语句查所有父级
常见问题,给一个记录ID,查出它的所有父级,直到顶级 使用SMSS,sql server,找到一个办法. 思路是分两步,先循环找到所有父级的ID,再用IN查出所有父级 列说明 ID=PK Pare ...
- 「ZJOI2016」旅行者 解题报告
「ZJOI2016」旅行者 对网格图进行分治. 每次从中间选一列,然后枚举每个这一列的格子作为起点跑最短路,进入子矩形时把询问划分一下,有点类似整体二分 至于复杂度么,我不会阿 Code: #incl ...
- UVA 11149-Power of Matrix(等比矩阵求和)
给定一个矩阵A 要求A + A^2 + A^3 +…. A^k: 对于到n的等比矩阵求和 如果n是偶数: 如果n是奇数: #include<stdio.h> #include<s ...
- A.01.03-模块的输入—模拟量输入
模拟量输入在使用过程中也十分常见,它在很多场合都应用到,但其用法又各有不同,下面列举一些常见的类型进行说明. 第一种为采用模拟口读取离散量的状态,如某开关可能有高.低.悬空三种状态均需能准确判断,这种 ...
- 【洛谷P2709】小B的询问
题目大意:给定一个长度为 N 的序列,M 个询问,静态查询区间 [l,r] 内的不同颜色数的平方和. 题解:直接莫队即可. 代码如下 #include <bits/stdc++.h> #d ...
- js小结
1,浏览器对json支持的方法: JSON.parse(jsonstr);将string转为json的对象. JSON.stringify(jsonobj);将json对象转为string. 2,js ...
- 关于json_encode转数组为json对象时里有数组格式数据的问题
前言:这次是给一款小程序提供接口时发现的 别的不多说,下面直接看出现问题的json数据 可以看到,这是一个大的json对象,是由多维数组组成,一般api接口提供的也是这种格式. 但是仔细看红框中的内容 ...