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,那么 ...
随机推荐
- hadoop-client
<!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-common --> <dependency> ...
- Micro Frontends
Micro Frontends - extending the microservice idea to frontend development https://micro-frontends.or ...
- searchkick HasMany Associations | index related model fields
Project < ActiveRecord::Base searchkick has_many :categories_has_projects has_many :categories, t ...
- 为了cider,尝试emacs的坑
https://github.com/clojure-emacs/cider http://clojure-doc.org/articles/tutorials/emacs.html emacs通过b ...
- vue中显示和隐藏导航
const router = new VueRouter({ mode: 'history', routes: [ { path: '/first', component: firstView, me ...
- MongoDB3.6.3 windows安装配置、启动
1.官网下载MongoDB的安装包 2.安装中一直Next即可安装成功,不过需要注意的是: 可以自定义安装,选择安装路径 值得注意的还有,安装中因为下载compass十分缓慢.把下面默认选中的勾去掉 ...
- Oracle:spool 的一个用法
spool 是sqlplus的一个语法,非sql. 平时,我们通过ssh或者xmanger连接到oracle后,如果我们想把我们在上面操作的脚本及脚本执行过程.结果保存下来的话,可以通过spool来实 ...
- 计算机科学 —— 时间戳(timestamp)
时间戳的一个重要属性即是:唯一性,以起到唯一标识的作用: 1. linux 命令行 $ date +%s 1506222745 2. Python 时间戳 内置 time 库 >> tim ...
- can't set android permissions - built without android support
/**************************************************************************** * can't set android pe ...
- [Selenium] Automation Test Manual(Selenium)
http://www.cnblogs.com/puresoul/p/3483055.html http://www.360doc.com/content/14/0913/10/13497042_409 ...