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. CentOS笔记-常用网络命令

    1.curl & wget 使用curl或wget命令,不用离开终端就可以下载文件.如你用curl,键入curl -O后面跟一个文件路径.wget则不需要任何选项.下载的文件在当前目录. cu ...

  2. 阿里巴巴Java开发手册(开发规范)——编程规约笔记

    2.常量规约 [推荐]如果变量值仅在一个范围内变化用Enum类. 如果还带有名称之外的延伸属性,必须使用Enum类, 下面正例中的数字就是延伸信息,表示星期几. 正例: public Enum{ MO ...

  3. intellij IDEA 更新java后不用重启tomcat

    最近项目大了,每次修改后重启都要等和很久,那个煎熬…… 为了解决这个问题,万能的Google  装了这个  JREBEL 5.63最新的 安装步骤: 一.IDEA在线搜索 jrebel  安装 二.破 ...

  4. “There's no Qt version assigned to this project for platform ” - visual studio plugin for Qt

    1.find menu "Qt VS Tools", select Qt Options 2.add a new Qt version 3. right click the tar ...

  5. node安装与升级

    node安装与升级 1.安装 sudo apt-get install nodejs sudo apt-get install npm 2.升级 如果node不是最新的,node有一个模块叫n,是专门 ...

  6. hdu-5718 Oracle(水题)

    题目链接: Oracle Time Limit: 8000/4000 MS (Java/Others)     Memory Limit: 262144/262144 K (Java/Others) ...

  7. [Selenium] The commonly used validation method

    Assert.assertTrue(tmpEl.getAttribute("class").contains("selected"),"The fol ...

  8. HTTP node静态资源请求加载demo

    MIME type的缩写为(Multipurpose Internet Mail Extensions)代表互联网媒体类型(Internet media type),MIME使用一个简单的字符串组成, ...

  9. 关于 .dyib 文件

    .dylib 意味着这是一个动态链接库. libz.dylib 是提供zip压缩.解压缩的库. 库的接口请 #import "zlib.h"

  10. vim 退出命令(保存、放弃保存)

    在命令模式中,连按两次大写字母Z,若当前编辑的文件曾被修改过,则Vi保存该文件后退出,返回到shell:若当前编辑的文件没被修改过,则Vi直接退出,   返回到shell. 在末行模式下,输入命令 : ...