题目: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. 【FAQ系列】Relay log 导致复制启动失败

    今天在使用冷备份文件重做从库时遇到一个报错,值得研究一下. 版本:MySQL5.6.27 一.报错现象 dba:(none)> start slave; ERROR (HY000): Slave ...

  2. goseq

    goseq是一个R包,用于寻找GO terms,即基因富集分析. GO terms是标准化描述基因或基因产物的词汇,包括三方面,cellular component,molecular funcito ...

  3. 【bzoj3240 && 洛谷P1397】矩阵游戏[NOI2013](矩阵乘法+卡常)

    题目传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=3240 这道题其实有普通快速幂+费马小定理的解法……然而我太弱了,一开始只想到了矩阵乘法的 ...

  4. js提示确认删除吗

    <script language="javascript"> function delcfm() { if (!confirm("确认要删除?")) ...

  5. mysql基础(4)-数据导入

    如何把数据导入(出)mysql 导出 sql语句         select * from 表名 into outfile "详细路径" fields terminated by ...

  6. 使用Properties读写属性文件

    import java.io.FileInputStream; import java.io.FileOutputStream; import java.util.Properties; /*Prop ...

  7. MATLAB中feval与eval的区别

    feval函数有两种调用形式1.[y1, y2, ...] = feval(fhandle, x1, ..., xn)2.[y1, y2, ...] = feval(fname, x1, ..., x ...

  8. nova Rescue 和 Unrescue

    usage: nova rescue [--password <password>] [--image <image>] <server> Reboots a se ...

  9. Windows Live Writer加载代码着色插件步骤

    博客园内置支持SyntaxHighlighter代码着色,代码着色语法:<pre class='brush:编程语言'>代码</pre>. 需要注意的是:如何你使用Syntax ...

  10. 为mac终端添加tree命令

    原文:http://superuser.com/questions/359723/mac-os-x-equivalent-of-the-ubuntu-tree-command/ 整理步骤如下: $ t ...