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优化的背包。。水过去了的更多相关文章

  1. 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 ...

  2. poj 1742 Coins(二进制拆分+bitset优化多重背包)

    \(Coins\) \(solution:\) 这道题很短,开门见山,很明显的告诉了读者这是一道多重背包.但是这道题的数据范围很不友好,它不允许我们直接将这一题当做01背包去做.于是我们得想一想优化. ...

  3. HDU 5890 Eighty seven(DP+bitset优化)

    题目链接 Eighty seven 背包(用bitset预处理)然后对于每个询问O(1)回答即可. 预处理的时候背包. #include <bits/stdc++.h> using nam ...

  4. HDU - 5887:Herbs Gathering (map优化超大背包)

    Collecting one's own plants for use as herbal medicines is perhaps one of the most self-empowering t ...

  5. 回滚线段树+bitset优化01背包——cf981E

    /*首先考虑如何计算一个点的可能凑出的值,这就是一个01可行性背包问题那么再拓展到一段区间[1..n]的点上,每个query都可以看做是一段区间上的点[l,r]加上一个体积为x的物品,转换到01背包上 ...

  6. HDU4460-Friend Chains-BFS+bitset优化

    bfs的时候用bitset优化一下. 水题 #include <cstdio> #include <cstring> #include <algorithm> #i ...

  7. 【HDU 5808】 Price List Strike Back (整体二分+动态规划)

    Price List Strike Back There are nn shops numbered with successive integers from 11 to nn in Bytelan ...

  8. hdu 5745 La Vie en rose DP + bitset优化

    http://acm.hdu.edu.cn/showproblem.php?pid=5745 这题好劲爆啊.dp容易想,但是要bitset优化,就想不到了. 先放一个tle的dp.复杂度O(n * m ...

  9. hdu 5036 Explosion bitset优化floyd

    http://acm.hdu.edu.cn/showproblem.php?pid=5036 题意就是给定一副有向图,现在需要走遍这n个顶点,一开始出发的顶点是这n个之中的随便一个. 如果走了1,那么 ...

随机推荐

  1. 在VS2010中使用MySQL-转载

    下面这篇文章进过测试,确实可以.记下来,留作记录. http://blog.sina.com.cn/s/blog_782496390100qjcu.html

  2. UIProgress控件的属性和方法

    进度条控件是IOS开发中一个简单的系统控件,使用总结如下: 初始化一个进度条: - (instancetype)initWithProgressViewStyle:(UIProgressViewSty ...

  3. mysql---列的选取原则

    列选择原则: :字段类型优先级 整型 > date,整型>浮点型,time > enum,char>varchar > blob 列的特点分析: 整型: 定长,没有国家/ ...

  4. 大O符号

    大O 就是 时间复杂度.时间复杂度是大概的描述一个算法的用时(实际上从侧面的表达了他的效率) 最好时间复杂度,通常指在最好情形下,这个算法用时.反之,最坏情况下的就是最坏时间复杂度.通常 冒泡算法 的 ...

  5. HDU1358 Period —— KMP 最小循环节

    题目链接:https://vjudge.net/problem/HDU-1358 Period Time Limit: 2000/1000 MS (Java/Others)    Memory Lim ...

  6. Unity5.6打包问题

    将unity切换到5.6版本后打Android包时,提示android sdk tools version低于compile version,于是更新了android-sdk(下载了Android-S ...

  7. [SoapUI] Common XPath expressions

    选取节点 表达式 描述 nodename 选取此节点的所有子节点. / 从根节点选取. // 从匹配选择的当前节点选择文档中的节点,而不考虑它们的位置. . 选取当前节点. .. 选取当前节点的父节点 ...

  8. [Selenium] 操作新弹出窗口之验证标题和内容

    1)验证标题 package com.learningselenium.normalwebdriver; import static org.junit.Assert.*; import java.u ...

  9. bzoj2384

    树状数组+KMP 匹配问题上KMP 但是问题在于如何判断两个位置相等,我们认为如果一个位置之前比他小的数数量相同那么就是相等. 那么我们用树状数组动态维护这个东西,每次跳nxt的时候用树状数组删除数. ...

  10. nable to load bean: type:com.opensymphony.xwork2.util.ValueStackFactory

    严重: Exception starting filter struts2 Unable to load bean: type:com.opensymphony.xwork2.util.ValueSt ...