题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4300

考虑 dp[ i ] 能从哪些 j 转移过来,就是那些 a[ j ] & a[ i ] != 0 的,也就是有至少1位公共的1;所以在30位上记录这一位是1的那些 a[ ] 中的 dp[ ] 最大值,就能转移了。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e5,M=;
int n,a[N],bin[M],c[M],lm,ans;
int rdn()
{
int ret=;bool fx=;char ch=getchar();
while(ch>''||ch<''){if(ch=='-')fx=;ch=getchar();}
while(ch>=''&&ch<='') ret=(ret<<)+(ret<<)+ch-'',ch=getchar();
return fx?ret:-ret;
}
int main()
{
int tp=;
n=rdn();for(int i=;i<=n;i++)a[i]=rdn(),tp=max(tp,a[i]);
while(tp)lm++,tp>>=; lm--;
bin[]=;for(int i=;i<=lm;i++)bin[i]=bin[i-]<<;
for(int i=;i<=n;i++)
{
int d=;
for(int j=;j<=lm&&bin[j]<=a[i];j++)
if(a[i]&bin[j])d=max(d,c[j]);
d++;
for(int j=;j<=lm&&bin[j]<=a[i];j++)
if(a[i]&bin[j])c[j]=max(c[j],d);
}
for(int j=;j<=lm;j++)ans=max(ans,c[j]);
printf("%d\n",ans);
return ;
}

bzoj 4300 绝世好题——DP的更多相关文章

  1. bzoj 4300: 绝世好题 dp

    4300: 绝世好题 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/problem.php ...

  2. HYSBZ(BZOJ) 4300 绝世好题(位运算,递推)

    HYSBZ(BZOJ) 4300 绝世好题(位运算,递推) Description 给定一个长度为n的数列ai,求ai的子序列bi的最长长度,满足bi&bi-1!=0(2<=i<= ...

  3. BZOJ 4300: 绝世好题 动态规划

    4300: 绝世好题 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=4300 Description 给定一个长度为n的数列ai,求ai的 ...

  4. 【递推】BZOJ 4300:绝世好题

    4300: 绝世好题 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 564  Solved: 289[Submit][Status][Discuss] ...

  5. bzoj 4300: 绝世好题

    4300: 绝世好题 Time Limit: 1 Sec  Memory Limit: 128 MB Description 给定一个长度为n的数列ai,求ai的子序列bi的最长长度,满足bi& ...

  6. bzoj 4300: 绝世好题【dp】

    设f[i][j]表示数列到i为止最后一项第j位为1的最大子序列长度,每次从i-1中1<<j&a[i]!=0的位+1转移来 然后i维是不需要的,答案直接在dp过程中去max即可 #i ...

  7. BZOJ 4300 绝世好题(位运算)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=4300 [题目大意] 给出一个序列a,求一个子序列b,使得&和不为0 [题解] ...

  8. bzoj 4300 绝世好题 —— 思路

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4300 记录一下 mx[j] 表示以第 j 位上是1的元素结尾的子序列长度最大值,转移即可. ...

  9. BZOJ 4300: 绝世好题 二进制

    对于每一个数字拆位,然后维护一个大小为 30 左右的桶即可. code: #include <bits/stdc++.h> #define N 100006 #define setIO(s ...

随机推荐

  1. 【CodeChef】Enormous Input Test

    The purpose of this problem is to verify whether the method you are using to read input data is suff ...

  2. JSP笔记05——生命周期(转)

    原始内容:https://www.tutorialspoint.com/jsp/jsp_life_cycle.htm 在这一章中,我们将讨论JSP的生命周期. 理解JSP低层次功能的关键在于——理解它 ...

  3. get_called_class--后期静态绑定("Late Static Binding")类的名称

    get_called_class--后期静态绑定("Late Static Binding")类的名称 string get_called_class ( void ) 获取静态方 ...

  4. debian内核代码执行流程(二)

    继续上一篇文章<debian内核代码执行流程(一)>未完成部分. acpi_bus_init调用acpi_initialize_objects,经过一系列复杂调用后输出下面信息: [ IN ...

  5. nodejs/REPL环境命令行操作命令

    1,输入node 进入node[REPL]环境 2,按两次[ctrl+c]退出node[REPL]环境 3,上箭头会查找上次输入的命令 4,cls清屏 5,tab键会自动补全路径 6,REPL环境

  6. java基础之bit、byte、char、String

    bit 位,二进制数据0或1 byte 字节,一个字节等于8位二进制数 char 字符, String 字符串,一串字符 常见转换 1 字母  = 1byte = 8 bit 1 汉字  = 2byt ...

  7. mongodb count 导致不正确的数量(mongodb count 一个坑)

    在mongodb 集群中,if  存在orphaned documents 和chunk migration, count查询可能会导致一个不正确的查询结果,例如我就是踩的这个坑,先不说话,看结果: ...

  8. SpringMVC传递参数和获取参数以及返回数据

    1.传递form表单,参数接收到对象,name和对象属性对应上即可:   2.springmvc不能直接通过form表单传递多个对象的list集合,要么采用ajax传递,要么采用封装了list属性的b ...

  9. mongod无法启动

    今天遇到了一个奇葩问题,我在Linux系统里备份了数据库,结果不知道为什么,系统用不了了,后来经过同事的检查,发现原来是我的硬盘快满了,导致mongod数据无法启动,真是.......

  10. UVA 11029 || Lightoj 1282 Leading and Trailing 数学

    Leading and Trailing You are given two integers: n and k, your task is to find the most significant ...