焦作网络赛K-Transport Ship【dp】
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
题目来源
题意:
有n种船 每种有2^c[i] - 1艘 每艘载重v[i]【必须完全装满】
现给出q次查询s 输出装载s的安排船的方案数
思路:
形如多重背包问题 用二进制的思想就行优化
dp[w]表示载重w时的方案数 他可由dp[w - v[i] * k]得到 其中k是系数
按照二进制的思想 每次k*=2 最多20次 并且判断和c[i]的关系
要注意因为是2^c[i] -1因此等号不能取
// ConsoleApplication3.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
// //#include "pch.h"
#include <iostream>
#include<algorithm>
#include<stdio.h>
#include<set>
#include<cmath>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack> #define inf 0x3f3f3f3f using namespace std;
typedef long long LL; const int maxn = ;
const int maxs = ;
const LL mod = ;
int t, n, q, s;
int v[maxn], c[maxn];
LL dp[maxs]; int main()
{
cin >> t;
while (t--) {
scanf("%d%d", &n, &q);
for (int i = ; i < n; i++) {
scanf("%d%d", &v[i], &c[i]);
} memset(dp, , sizeof(dp));
dp[] = ; int k = ;
for (int j = ; j < ; j++) {
for (int i = ; i < n; i++) {
if (j >= c[i]) {
continue;
}
for (int w = maxs; w >= v[i] * k; w--) {
dp[w] += dp[w - k * v[i]];
dp[w] %= mod;
}
}
k *= ;
} while (q--) {
scanf("%d", &s);
printf("%lld\n", dp[s]);
}
}
}
焦作网络赛K-Transport Ship【dp】的更多相关文章
- 2018 焦作网络赛 K Transport Ship ( 二进制优化 01 背包 )
题目链接 题意 : 给出若干个物品的数量和单个的重量.问你能不能刚好组成总重 S 分析 : 由于物品过多.想到二进制优化 其实这篇博客就是存个二进制优化的写法 关于二进制优化的详情.百度一下有更多资料 ...
- 【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 ...
- 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 (多重背包)
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 ...
- ACM-ICPC2018焦作网络赛 Mathematical Curse(dp)
Mathematical Curse 22.25% 1000ms 65536K A prince of the Science Continent was imprisoned in a cast ...
- ACM-ICPC 2018 焦作网络赛
题目顺序:A F G H I K L 做题链接 A. Magic Mirror 题意:判断 给出的 字符串 是否等于"jessie",需要判断大小写 题解:1.用stl库 tolo ...
- 2019-ACM-ICPC-沈阳区网络赛-K. Guanguan's Happy water-高斯消元+矩阵快速幂
2019-ACM-ICPC-沈阳区网络赛-K. Guanguan's Happy water-高斯消元+矩阵快速幂 [Problem Description] 已知前\(2k\)个\(f(i)\),且 ...
- ACM-ICPC2018焦作网络赛 Transport Ship(二进制背包+方案数)
Transport Ship 25.78% 1000ms 65536K There are NN different kinds of transport ships on the port. T ...
随机推荐
- OPenGL 库文件的添加
OPenGL使用前必须添加一些必要的库文件: 需要安装 GLUT 工具包: GLUT下载地址 GLAUX下载地址 Windows 环境下安装 GLUT 的步骤:1.将下载的压缩包解开,将得到 5 ...
- buildroot制作文件系统
/******************************************************************* * buildroot制作文件系统 * 使用buildroot ...
- 严格控制GOTO语句
注意事项 1,使用顺序.选择.循环等有限的基本结构表示程序逻辑. 2,选用的控制结构只准许有一个入口和一个出口 3,程序语句组成容易识别的块,每块只有一个入口和一个出口. 4,复杂结构应该用基本控制结 ...
- 演示-JQuery属性选择器
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- apache基金会开源项目简介
apache基金会开源项目简介 项目名称 描述 HTTP Server 互联网上首屈一指的HTTP服务器 Abdera Apache Abdera项目的目标是建立一个功能完备,高效能的IETF ...
- jQuery继承extend用法详解
/直接基于jQuery的扩展,判断是否为空 $.isBlank = function(obj){ return(typeof(obj)=='undefined'||obj==''||obj==nu ...
- 安装SQL Server 2008数据库(带完整图解)
方法/步骤 1 双击sql server 2008的.exe安装文件,进入[SQL Server 安装中心]. 2 点击界面左侧的[安装],然后点击右侧的[全新SQL Server 独立安装或向现 ...
- VMWare虚拟机提示:打不开磁盘…或它所依赖的某个快照磁盘,开启模块DiskEarly的操作失败,未能启动虚拟机
将电脑上存在的虚拟机复制一份后打开运行,弹出错误提示: 打不开磁盘…或它所依赖的某个快照磁盘,开启模块DiskEarly的操作失败,未能启动虚拟机. 解决方法如下: 打开存放虚拟机系统硬盘的所在文件夹 ...
- 如何通过phoenix中查看表的主键信息
需求描述: 今天一个开发的同事让帮忙查看下表的主键列,在此记录下. 操作过程: 1.通过!primarykeys命令查看表的主键 !primarykeys SYNC_BUSINESS_INFO_BYD ...
- linux环境中,nginx安装过程
需求描述: 记录在linux平台,nginx安装的过程. 环境描述: 操作系统:Red Hat Enterprise Linux Server release 6.6 (Santiago) 操作内核版 ...