HDU 5808 Price List Strike Back bitset优化的背包。。水过去了
http://acm.hdu.edu.cn/showproblem.php?pid=5808
用bitset<120>dp,表示dp[0] = true,表示0出现过,dp[100] = true表示100这个数字出现过。
对于每一个新的数字,val,有转移方程,
dp = dp | (dp << val)
比如现在0000101,然后枚举了2进来,0000101 | 0010100
那个区间是暴力扫过去的,是水过去的,关键学了下bitset优化的背包。
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset>
vector<int>vc[];
const int maxn = + ;
int dis[maxn];
char ans[ + ];
void init() {
for (int i = ; i <= ; ++i) vc[i].clear();
}
void work() {
init();
int n, m;
scanf("%d%d", &n, &m);
for (int i = ; i <= n; ++i) {
int price;
scanf("%d", &price);
vc[price].push_back(i);
}
for (int i = ; i <= n; ++i) {
scanf("%d", &dis[i]);
}
for (int i = ; i <= m; ++i) {
int L, R, mostDis, sum;
scanf("%d%d%d%d", &L, &R, &mostDis, &sum);
bitset<>dp;
dp[] = ;
bool flag = false;
for (int j = ; j <= && !flag; ++j) {
if (vc[j].size() == ) continue;
int lo = lower_bound(vc[j].begin(), vc[j].end(), L) - vc[j].begin();
int up = upper_bound(vc[j].begin(), vc[j].end(), R) - vc[j].begin();
up--;
for (int k = lo; k <= up; ++k) {
if (dis[vc[j][k]] > mostDis) continue;
dp = dp | (dp << j);
if (dp[sum]) {
flag = true;
break;
}
}
}
if (!flag) {
ans[i] = '';
} else ans[i] = '';
}
ans[m + ] = '\0';
printf("%s\n", ans + );
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
int t;
scanf("%d", &t);
while (t--) work();
return ;
}
HDU 5808 Price List Strike Back bitset优化的背包。。水过去了的更多相关文章
- hdu 5506 GT and set dfs+bitset优化
GT and set Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Probl ...
- poj 1742 Coins(二进制拆分+bitset优化多重背包)
\(Coins\) \(solution:\) 这道题很短,开门见山,很明显的告诉了读者这是一道多重背包.但是这道题的数据范围很不友好,它不允许我们直接将这一题当做01背包去做.于是我们得想一想优化. ...
- HDU 5890 Eighty seven(DP+bitset优化)
题目链接 Eighty seven 背包(用bitset预处理)然后对于每个询问O(1)回答即可. 预处理的时候背包. #include <bits/stdc++.h> using nam ...
- HDU - 5887:Herbs Gathering (map优化超大背包)
Collecting one's own plants for use as herbal medicines is perhaps one of the most self-empowering t ...
- 回滚线段树+bitset优化01背包——cf981E
/*首先考虑如何计算一个点的可能凑出的值,这就是一个01可行性背包问题那么再拓展到一段区间[1..n]的点上,每个query都可以看做是一段区间上的点[l,r]加上一个体积为x的物品,转换到01背包上 ...
- HDU4460-Friend Chains-BFS+bitset优化
bfs的时候用bitset优化一下. 水题 #include <cstdio> #include <cstring> #include <algorithm> #i ...
- 【HDU 5808】 Price List Strike Back (整体二分+动态规划)
Price List Strike Back There are nn shops numbered with successive integers from 11 to nn in Bytelan ...
- hdu 5745 La Vie en rose DP + bitset优化
http://acm.hdu.edu.cn/showproblem.php?pid=5745 这题好劲爆啊.dp容易想,但是要bitset优化,就想不到了. 先放一个tle的dp.复杂度O(n * m ...
- hdu 5036 Explosion bitset优化floyd
http://acm.hdu.edu.cn/showproblem.php?pid=5036 题意就是给定一副有向图,现在需要走遍这n个顶点,一开始出发的顶点是这n个之中的随便一个. 如果走了1,那么 ...
随机推荐
- CentOS笔记-常用网络命令
1.curl & wget 使用curl或wget命令,不用离开终端就可以下载文件.如你用curl,键入curl -O后面跟一个文件路径.wget则不需要任何选项.下载的文件在当前目录. cu ...
- Shell编程——Shell中的数学运算
在Linux Shell中进行数学运算,通常能够使用的运算符有: 简单运算: let [] (()) 高级运算: expr bc 1.let命令 let命令是bash内置命令.能够实现简单的算术以及逻 ...
- gitbash使用
gitbash是什么 git bash是Windows下的命令行工具. 基于msys GNU环境,有git分布式版本控制工具. 主要用于git版本控制,上传下载项目代码. GNU环境,就是说如果你喜欢 ...
- POJ1511 Invitation Cards —— 最短路spfa
题目链接:http://poj.org/problem?id=1511 Invitation Cards Time Limit: 8000MS Memory Limit: 262144K Tota ...
- WPF之Binding深入探讨 转载:http://blog.csdn.net/fwj380891124/article/details/8107646
1,Data Binding在WPF中的地位 程序的本质是数据+算法.数据会在存储.逻辑和界面三层之间流通,所以站在数据的角度上来看,这三层都很重要.但算法在3层中的分布是不均匀的,对于一个3层结构的 ...
- JavaScript-Tool:wdtree
ylbtech-JavaScript-Tool:wdtree 1.返回顶部 1. 插件描述:wdTree是一个轻量级jQuery插件用于创建一个带有嵌套Check Boxe的树形控件. wdTree是 ...
- JS按字节截取字符长度实例
处理过长的字符串,截取并添加省略号 * 注:半角长度为1,全角长度为2 * * pStr:字符串 * pLen:截取长度 * * return: 截取后的字符串 * 代码如下: function ...
- nable to load bean: type:com.opensymphony.xwork2.util.ValueStackFactory
严重: Exception starting filter struts2 Unable to load bean: type:com.opensymphony.xwork2.util.ValueSt ...
- CodeForces 718C && HDU 3572 && Constellation
Point 1. 区间乘以一个数/矩阵的幂时,不要用指数相加的方法. 而要用直接维护mulv[x]表示区间要乘多少. 不然的话,空加一个logn 2. 要点在于,冲突的点连边,形成二分图,对于在同一个 ...
- UVa 1611 Crane (构造+贪心)
题意:给定一个序列,让你经过不超过9的6次方次操作,变成一个有序的,操作只有在一个连续区间,交换前一半和后一半. 析:这是一个构造题,我们可以对第 i 个位置找 i 在哪,假设 i 在pos 位置, ...