焦作网络赛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 ...
随机推荐
- Runtime是什么?
在看 RPC 的概念模型与实现解析 的时候,看到图片上有Runtime,又想到见过很多Runtime之类的东西,所以就想弄明白这到底是个什么东西. (因为是程序名,所以根本没想到代码的“编译-运行”~ ...
- 第二百九十三,Memcached缓存
Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速度.Memcached ...
- nodejs基础 -- 函数
Node.js 函数 在JavaScript中,一个函数可以作为另一个函数接收一个参数.我们可以先定义一个函数,然后传递,也可以在传递参数的地方直接定义函数. Node.js中函数的使用与Javasc ...
- 详细分析css float 属性以及position:absolute 的区别
1.float 属性定义元素在哪个方向浮动.以往这个属性总应用于图像,使文本围绕在图像周围,不过在 CSS 中,任何元素都可以浮动.浮动元素会生成一个块级框,而不论它本身是何种元素.div一个典型的块 ...
- VS 清除编译产生的临时文件、文件夹
VS编译过程中会产生一些临时文件,通过以下脚本可清除 @echo off for /r %%i in (*.sdf,*.ncb,*.suo,*.exp,*.user,*.aps,*.idb,*.dep ...
- work,i/o最小线程设置
设置work i/o最小线程有两种方式1.通过配置文件设置,影响所有iis部署程序(待验证)2.通过程序代码设置,iis上部署的程序互不影响int minWorker, minIOC; //Get t ...
- day17<集合框架+>
集合框架(HashSet存储字符串并遍历) 集合框架(HashSet存储自定义对象保证元素唯一性) 集合框架(HashSet存储自定义对象保证元素唯一性图解及代码优化) 集合框架(HashSet如何保 ...
- Python 爬虫知识点 - 淘宝商品检索结果抓包分析(续一)
通过前一节得出地址可能的构建规律,如下: https://s.taobao.com/search?data-key=s&data-value=44&ajax=true&_ksT ...
- Java取出字符串中的大写字母,并倒序输出
package catic.test; /** * @ClassName: TestXBQ * @Description: TODO 输出字符串中的大写字母,并倒序输出 * @author xbq * ...
- 新唐ARM9之NUC972学习历程之系统的搭建和BSP包的使用
说到嵌入式,我们首先想到的,就是它的复杂程度,LINUX,BSP,UBOOT,交叉编译,寄存器配置,等等一系列的问题,甚至有的时候我们对此一头雾水,很是头疼,不过我们今天要说的就是关于NUC972的一 ...