loj515 「LibreOJ β Round #2」贪心只能过样例
传送门:https://loj.ac/problem/515
【题解】
容易发现S最大到1000000。
于是我们有一个$O(n^2*S)$的dp做法。
容易发现可以被bitset优化。
于是复杂度就是$O(\frac{n^2S}{32})$
然后……就过了
# include <bitset>
# include <stdio.h>
# include <string.h>
# include <iostream>
# include <algorithm>
// # include <bits/stdc++.h> using namespace std; typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int M = 1e6 + , N = + ;
const int mod = 1e9+; int n, a[N], b[N], cnt; bitset<> f[]; int main() {
cin >> n;
for (int i=; i<=n; ++i) cin >> a[i] >> b[i];
int pre = , cur = ;
f[][] = ;
for (int i=; i<=n; ++i) {
f[cur].reset();
for (int j=a[i]; j<=b[i]; ++j)
f[cur] |= (f[pre] << j*j);
swap(cur, pre);
}
for (int i=; i<=; ++i)
if(f[pre][i]) ++cnt;
cout << cnt << endl;
return ;
}
loj515 「LibreOJ β Round #2」贪心只能过样例的更多相关文章
- loj515 「LibreOJ β Round #2」贪心只能过样例[bitset+bool背包]
由于bitset极其不熟练且在实际题目中想不起来运用它来优化,于是练了几道题. 这题是一个分组的bool背包,每组必须选一个,暴力的话是$O(n^5)$. 如果dp数组不要一维滚动的话,有两种枚举方法 ...
- Loj515 「LibreOJ β Round #2」贪心只能过样例 - Bitset,Dp
bitset的基本应用了 类似可行性背包的dp考虑 复杂度O(nmL/64) #include <bits/stdc++.h> using namespace std; bitset &l ...
- [LOJ#515]「LibreOJ β Round #2」贪心只能过样例
[LOJ#515]「LibreOJ β Round #2」贪心只能过样例 试题描述 一共有 \(n\) 个数,第 \(i\) 个数 \(x_i\) 可以取 \([a_i , b_i]\) 中任意值. ...
- LOJ#515. 「LibreOJ β Round #2」贪心只能过样例(bitset)
内存限制:256 MiB时间限制:1000 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: nzhtl1477 提交提交记录统计讨论测试数据 题目描述 一共有 nnn个数,第 iii ...
- LibreOJ #515. 「LibreOJ β Round #2」贪心只能过样例
题目描述 一共有 nnn个数,第 iii 个数 xix_ixi 可以取 [ai,bi][a_i , b_i][ai,bi] 中任意值.设 S=∑xi2S = \sum{{x_i}^2 ...
- LibreOJ β Round #2」贪心只能过样例
题目友链:https://loj.ac/problem/515 话说这题蛮简单,bitset暴力直接过. 话不多说,上代码! #include <bits/stdc++.h> using ...
- 「LibreOJ#515」贪心只能过样例 (暴力+bitset)
可以发现,答案最大值只有106,于是想到用暴力维护 可以用bitset合并方案可以优化复杂度, Code #include <cstdio> #include <bitset> ...
- LOJ528 「LibreOJ β Round #4」求和
LOJ528 「LibreOJ β Round #4」求和 先按照最常规的思路推一波: \[\begin{aligned} &\sum_{i=1}^n\sum_{j=1}^m\mu^2(\gc ...
- loj #547. 「LibreOJ β Round #7」匹配字符串
#547. 「LibreOJ β Round #7」匹配字符串 题目描述 对于一个 01 串(即由字符 0 和 1 组成的字符串)sss,我们称 sss 合法,当且仅当串 sss 的任意一个长度为 ...
随机推荐
- holoeverywhere修改actionbar背景
<style name="Holo.Theme.Light.MyActionBar" parent="Holo.Base.Theme.Light.DarkActio ...
- 关于CString总结
前言:串操作是编程中最常用也最基本的操作之一. 做为VC程序员,无论是菜鸟或高手都曾用过CString.而且好像实际编程中很难离得开它(虽然它不是标准C++中的库).因为MFC中提供的这个类对 我们操 ...
- js移动端滑块验证解锁组件
本文修改自PC端的js滑块验证组件,PC端使用的是onmousedown,onmouseup,nomousemove.原文找不到了,也是博客园文章,在此感谢广大网友的生产力吧. 说下对插件和组件的理解 ...
- union查询
select id, uid, money, FROM_UNIXTIME(created) as created, type FROM ( #type=1是 cjw_finance_bonus ...
- sublime text 输入法不跟随光标
1.引子 sublime text 有个BUG,那就是不支持中文的鼠标跟随(和PS类似输入的光标和文字候选框不在一起).如下图: 2.插件 安装IMESupport插件即可插件,这款插件是日本人写的. ...
- 【bzoj4579】[Usaco2016 Open]Closing the Farm 并查集
题目描述 Farmer John and his cows are planning to leave town for a long vacation, and so FJ wants to tem ...
- WPF 进度条ProgressBar
今天研究了一下wpf的进度条ProgressBar 1.传统ProgressBar WPF进度条ProgressBar 这个控件,如果直接写到循环里,会死掉,界面会卡死,不会有进度.需要把进度条放到单 ...
- [ZJOI2010]贪吃的老鼠 网络流
---题面--- 题解: 这是一道强题emmmm,做法非常巧妙,,,我也是看了好久大佬题解才看明白一点 首先考虑没有限制的情况,即n个老鼠可以在同一时刻吃同一块奶酪 对各个时间段拆点,连奶酪 ---& ...
- POJ2826:An Easy Problem?!——题解(配特殊情况图)
http://poj.org/problem?id=2826 题目大意:给两条线,让它接竖直下的雨,问其能装多少横截面积的雨. ———————————————————————————— 水题,看题目即 ...
- BZOJ4568:[SCOI2016]幸运数字——题解
https://www.lydsy.com/JudgeOnline/problem.php?id=4568 https://www.luogu.org/problemnew/show/P3292 A ...