焦作网络赛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 ...
随机推荐
- 使用ffmpeg步骤
av_register_all();//初始化ffmpeg库,如果系统里面的ffmpeg没配置好这里会出错 if (isNetwork) { //需要播放网络视频 avforma ...
- JS中setInterval、setTimeout不能传递带参数的函数的解决方法
setInterval 和 setTimeout 这两个函数比较好用,但会遇到比如说我隔个几秒后要执行的函数是带参数的,这种情况怎么办?可以用匿名函数包装处理 //不带参数的函数 function t ...
- 下载最新android adt的方法
作为一名android开发人员,需要经常更新最新版本的 android adt,但是直接到官网去找很难找到下载的链接,通过下面现成的链接,你就能够直接下载最新的android adt了, 网址是:de ...
- Centos6.8/7.0搭建Git服务http访问方式
安装Git版本:git 2.10.0 Git访问方式:基于http的基本验证(非SSL) 1. 安装Apache软件: [root@localhost ~]# yum install httpd 设置 ...
- 动态提交使用jQuery 完成ajax 文件下载----后端php
1.js代码 // Ajax 文件下载 //当不用传参时,可以将data去掉 jQuery.download = function(url, data, method){ // 获得url和data ...
- asp.net截屏功能实现截取web页面
using System.Drawing; //打开该页面 System.Diagnostics.Process.Start("IEXPLORE.EXE", "http ...
- NGUI之scroll view的制作和踩坑总结
之前也看了不少童鞋谢了关于NGUI的scroll view的制作下面我写下自己的制作过程以及心得,希望对童鞋们有所帮助.1.首先建立一个960*640的背景参考http://game.ceeger.c ...
- ios iOS手势识别的详细使用(拖动,缩放,旋转,点击,手势依赖,自定义手势)
iOS手势识别的详细使用(拖动,缩放,旋转,点击,手势依赖,自定义手势) 转自容芳志大神的博客:http://www.cnblogs.com/stoic/archive/2013/02/27/2940 ...
- java运行显示“找不到或无法加载主类”的解决办法(linux)
要是配置文件的路径问题.打开终端,输入vi ~/.bashrc添加如下代码即可. # set Java environmentJAVA_HOME=/usr/local/java/jdk1.8.0PAT ...
- Nginx 0.8.x + PHP 5.2.13(FastCGI)搭建胜过Apache十倍的Web服务器[摘抄]
[文章作者:张宴 本文版本:v6.3 最后修改:2010.07.26 转载请注明原文链接:http://blog.s135.com/nginx_php_v6/] 前言:本文是我撰写的关于搭建“Ngin ...