ACM-ICPC 2018 焦作赛区网络预赛 K. Transport Ship(DP)
题目链接:https://nanti.jisuanke.com/t/31720
题意:有n种飞船,每种飞船有(1 << c)- 1 艘,容量为 k[i] ,q 次询问,每次询问选若干艘飞船使得容量为 s 的方案数。
题解:预处理出全部情况。dp[ i ][ j ]表示选前 i 个物品凑出容量为 k 的方案数,转移的时候可注意到dp[ i ][ j ] = sigma(dp[i - 1][j - x * v ]),然后减掉不合法的情况(x > ( (1 << c) - 1) )。详见代码~
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LL __int128
#define ull unsigned long long
#define mst(a,b) memset((a),(b),sizeof(a))
#define mp(a,b) make_pair(a,b)
#define fi first
#define se second
#define pi acos(-1)
#define pii pair<int,int>
#define pb push_back
const int INF = 0x3f3f3f3f;
const double eps = 1e-;
const int MAXN = 1e4 + ;
const int MAXM = 1e6 + ;
const ll mod = 1e9 + ; ll dp[][MAXN]; int main()
{
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
int t;
scanf("%d",&t);
while(t--) {
int n,q;
scanf("%d%d",&n,&q);
mst(dp, );
dp[][] = ;
for(int i = ; i <= n; i++) {
int c,v;
scanf("%d%d",&v,&c);
c = ( << c) * v;
for(int j = ; j < v; j++) dp[i][j] = dp[i - ][j];
for(int j = v; j <= ; j++) {
dp[i - ][j] += dp[i - ][j - v];
if(dp[i - ][j] >= mod) dp[i - ][j] -= mod;
dp[i][j] = dp[i - ][j];
if(j >= c) {
dp[i][j] -= dp[i - ][j - c];
if(dp[i][j] < ) dp[i][j] += mod;
}
}
}
while(q--) {
int s;
scanf("%d",&s);
printf("%lld\n",dp[n][s]);
}
}
return ;
}
ACM-ICPC 2018 焦作赛区网络预赛 K. Transport Ship(DP)的更多相关文章
- ACM-ICPC 2018 焦作赛区网络预赛 K Transport Ship (多重背包)
https://nanti.jisuanke.com/t/31720 题意 t组样例,n种船只,q个询问,接下来n行给你每种船只的信息:v[i]表示这个船只的载重,c[i]表示这种船只有2^(c[i] ...
- 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 焦作赛区网络预赛 B Mathematical Curse(DP)
https://nanti.jisuanke.com/t/31711 题意 m个符号必须按顺序全用,n个房间需顺序选择,有个初始值,问最后得到的值最大是多少. 分析 如果要求出最大解,维护最大值是不能 ...
- 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 ...
随机推荐
- 2019华东交通大学ACM基地简介
一.基地成就简介: ACM国际大学生程序设计竞赛(英文全称:ACM International Collegiate Programming Contest(简称ACM-ICPC或ICPC))是由国际 ...
- kafka producer partitions分区器(七)
消息在经过拦截器.序列化后,就需要确定它发往哪个分区,如果在ProducerRecord中指定了partition字段,那么就不再需要partitioner分区器进行分区了,如果没有指定,那么会根据k ...
- [百家号]7nm ARM 64核!华为Hi1620高性能CPU公开:3.0GHz
7nm ARM 64核!华为Hi1620高性能CPU公开:3.0GHz https://baijiahao.baidu.com/s?id=1617735663824201180&wfr=spi ...
- Oracle存储过程——日常记录
代码规范 Oracle存储过程,关键字大写,变量小写并以v_开头,规范代码,提高可读性 赋值与判断符号 Oracle存储过程,变量赋值使用 := 符号,条件判断直接用 = 符号. 变量声明需在 beg ...
- 使用pycharm开发web——django2.1.5(二)创建一个app并做一些配置
这里我学习的呢是刘江老师的站,主要原因在于他这个版本新,还比较细节 网址先留一手,约等于在引用http://www.liujiangblog.com/ 开始正题: 1.在pycharm界面终端命令行里 ...
- idea启动tomcat时报错:Error during artifact deployment. See server log for details.
Error during artifact deployment. See server log for details. 这个很多人都找不出来,原因无非2个: 一.jar 包有有些没能识别,tomc ...
- Spring实战(四)Spring高级装配中的bean profile
profile的原意为轮廓.剖面等,软件开发中可以译为“配置”. 在3.1版本中,Spring引入了bean profile的功能.要使用profile,首先要将所有不同的bean定义整理到一个或多个 ...
- DSN 建立达梦7(DM)连接
(DSN)Data Source Name 数据源名称 “ODBC数据源管理器”提供了三种DSN,分别为用户DSN.系统DSN和文件DSN.其中: 用户DSN会把相应的配置信息保存在Wind ...
- 使用 pdb 进行调试
使用 pdb 进行调试 pdb 是 python 自带的一个包,为 python 程序提供了一种交互的源代码调试功能,主要特性包括设置断点.单步调试.进入函数调试.查看当前代码.查看栈片段.动态改变变 ...
- Git忽略已追踪文件或文件夹
今天拉取代码,用vs生成后发现obj文件夹下自动生成的文件被同事提交了,这个本应该加入到ignore的 我就需要把这个文件夹加入到gitignore, 不过已经追踪的文件和文件夹,直接添加到gitig ...