传送门: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」贪心只能过样例的更多相关文章

  1. loj515 「LibreOJ β Round #2」贪心只能过样例[bitset+bool背包]

    由于bitset极其不熟练且在实际题目中想不起来运用它来优化,于是练了几道题. 这题是一个分组的bool背包,每组必须选一个,暴力的话是$O(n^5)$. 如果dp数组不要一维滚动的话,有两种枚举方法 ...

  2. Loj515 「LibreOJ β Round #2」贪心只能过样例 - Bitset,Dp

    bitset的基本应用了 类似可行性背包的dp考虑 复杂度O(nmL/64) #include <bits/stdc++.h> using namespace std; bitset &l ...

  3. [LOJ#515]「LibreOJ β Round #2」贪心只能过样例

    [LOJ#515]「LibreOJ β Round #2」贪心只能过样例 试题描述 一共有 \(n\) 个数,第 \(i\) 个数 \(x_i\) 可以取 \([a_i , b_i]\) 中任意值. ...

  4. LOJ#515. 「LibreOJ β Round #2」贪心只能过样例(bitset)

    内存限制:256 MiB时间限制:1000 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: nzhtl1477 提交提交记录统计讨论测试数据   题目描述 一共有 nnn个数,第 iii ...

  5. LibreOJ #515. 「LibreOJ β Round #2」贪心只能过样例

    题目描述 一共有 nnn个数,第 iii 个数 xix_ix​i​​ 可以取 [ai,bi][a_i , b_i][a​i​​,b​i​​] 中任意值.设 S=∑xi2S = \sum{{x_i}^2 ...

  6. LibreOJ β Round #2」贪心只能过样例

    题目友链:https://loj.ac/problem/515 话说这题蛮简单,bitset暴力直接过. 话不多说,上代码! #include <bits/stdc++.h> using ...

  7. 「LibreOJ#515」贪心只能过样例 (暴力+bitset)

    可以发现,答案最大值只有106,于是想到用暴力维护 可以用bitset合并方案可以优化复杂度, Code #include <cstdio> #include <bitset> ...

  8. LOJ528 「LibreOJ β Round #4」求和

    LOJ528 「LibreOJ β Round #4」求和 先按照最常规的思路推一波: \[\begin{aligned} &\sum_{i=1}^n\sum_{j=1}^m\mu^2(\gc ...

  9. loj #547. 「LibreOJ β Round #7」匹配字符串

    #547. 「LibreOJ β Round #7」匹配字符串   题目描述 对于一个 01 串(即由字符 0 和 1 组成的字符串)sss,我们称 sss 合法,当且仅当串 sss 的任意一个长度为 ...

随机推荐

  1. 计算器软件实现系列(七)WPF+SQL+策略模式

    一  整体概述 本次设计主要是在WPF的页面中实现的,属于表现层的更换,数据库部分用的还是数据库的封装,其中引用了策略模式 二  设计思路 1 在出题页面,进行试题的编辑,在编辑后会自动保存到数据库中 ...

  2. lintcode-191-乘积最大子序列

    191-乘积最大子序列 找出一个序列中乘积最大的连续子序列(至少包含一个数). 样例 比如, 序列 [2,3,-2,4] 中乘积最大的子序列为 [2,3] ,其乘积为6. 标签 子数组 领英 动态规划 ...

  3. lintcode-31-数组划分

    数组划分 给出一个整数数组 nums 和一个整数 k.划分数组(即移动数组 nums 中的元素),使得: 所有小于k的元素移到左边 所有大于等于k的元素移到右边 返回数组划分的位置,即数组中第一个位置 ...

  4. lintcode-28-搜索二维矩阵

    搜索二维矩阵 写出一个高效的算法来搜索 m × n矩阵中的值. 这个矩阵具有以下特性: 每行中的整数从左到右是排序的. 每行的第一个数大于上一行的最后一个整数. 样例 考虑下列矩阵: [ [1, 3, ...

  5. erlang+thrift配合开发

    I  think, thrift is a  tcp/ip based Client-Server architecture multi-languages supported RPC framewo ...

  6. linux+Nginx+Mysql+PHP环境下,安装mysqli模块

    奶奶的腿儿啊,太不易了.倒腾了小半天儿,写此随笔,待后查. 阿里云ecs中,安装phpcms,出现了一个问题:环境检测的时候,一直提示 Mysqli扩展没开启. 老夫哪儿特么会这么专业的啊...能咋办 ...

  7. JSON字符串书写

      { "XXX公司": [ { "name": "IT部", "mebers": [ { "维护人员&quo ...

  8. MVC 枚举 转 SelectListItem

    ViewBag.userlevel = new SelectList(Enum.GetNames(typeof(AdminLevels)),"", "", te ...

  9. java获取时间整点工具代码

    /**获取上n个小时整点小时时间 * @param date * @return */ public static String getLastHourTime(Date date,int n){ C ...

  10. 转:Simple Introduction to Dirichlet Process

    来源:http://hi.baidu.com/vyfrcemnsnbgxyd/item/2f10ecc3fc35597dced4f88b Dirichlet Process(DP)是一个很重要的统计模 ...