4300: 绝世好题

Time Limit: 1 Sec  Memory Limit: 128 MB

Description

给定一个长度为n的数列ai,求ai的子序列bi的最长长度,满足bi&bi-1!=0(2<=i<=len)。
 

Input

输入文件共2行。
第一行包括一个整数n。
第二行包括n个整数,第i个整数表示ai。
 

Output

输出文件共一行。
包括一个整数,表示子序列bi的最长长度。
 

Sample Input

3
1 2 3

Sample Output

2

HINT

n<=100000,ai<=2*10^9

Source

#include<cstdio>
#define N 100010
inline int max(int a,int b){return a>b?a:b;}
inline int read()
{
int tmp=;
char ch=getchar();
while(ch<''||ch>'') ch=getchar();
while(ch>=''&&ch<=''){tmp=tmp*+ch-'';ch=getchar();}
return tmp;
}
int t,n,a[N],f[],ans;
int main()
{
n=read();
for(int i=;i<n;i++)
{
t=read();
int tmp=;
for(int j=;j<;j++)
if(t&(<<j)) tmp=max(f[j]+,tmp);
for(int j=;j<;j++)
if(t&(<<j)) f[j]=tmp;
ans=max(ans,tmp);
}
printf("%d",ans);
}

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

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

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

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

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

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

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

  4. bzoj 4300: 绝世好题 dp

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

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

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

  6. bzoj 4300 绝世好题——DP

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4300 考虑 dp[ i ] 能从哪些 j 转移过来,就是那些 a[ j ] & a[ ...

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

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

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

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

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

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

随机推荐

  1. flex 正则 验证

    验证数字:^[-]*$ 验证n位的数字:^\d{n}$ 验证至少n位数字:^\d{n,}$ 验证m-n位的数字:^\d{m,n}$ 验证零和非零开头的数字:^(|[-][-]*)$ 验证有两位小数的正 ...

  2. mysql查询数据返回touple改为字典的方法

    conn = MySQLdb.connect(host='ip',user='root',passwd='123456',db="dbname",charset="utf ...

  3. 根据IP获取省市 .

    public class IPAddress { /// <summary> /// 得到真实IP以及所在地详细信息(Porschev) /// </summary> /// ...

  4. 模板(Template)

    最近阅读google chromium base container stack_container代码,深刻感觉到基础知识不扎实. // Casts the buffer in its right ...

  5. iOS静态库.a文件制作和导入使用

    iOS静态库.a文件制作: 1.新建Cocoa Touch Static Library工程 新建工程 - 选择iOS-FrameWork&Libary,选择 Cocoa Touch Stat ...

  6. Tomcat Xms Xmx PermSize MaxPermSize 区别 及 java.lang.OutOfMemoryError: PermGen space 解决

    解决方案 在 catalina.bat 里的 蓝色代码前加入: 红色代码 rem ----- Execute The Requested Command ----------------------- ...

  7. 远程桌面Default.rdp 中各个参数的含义(转)

    存储在 Default.rdp 文件中的设置 默认情况下,将在“我的文档”文件夹中创建 Default.rdp 文件.以下 RDP 设置存储在 Desktop.rdp 文件中: desktopwidt ...

  8. CodeIgnitor 创建admin和其他目录,前后端分离,很巧妙的方式,网上查找其他的都不是使用这种方式实现的。

    在index.php的第97和98行的注释, // The directory name, relative to the "controllers" folder. Leave ...

  9. a:link,a:visited,a:hover,a:active

    1:解释 link:连接平常的状态 visited:连接被访问过之后 hover:鼠标放到连接上的时候 active:连接被按下的时候      详细的: :hover版本:CSS1/CSS2 兼容性 ...

  10. MongoDB介绍与windows下安装

    MongoDB是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的.他支持的数据结构非常松散,是类 似json的bjson格式,因此可以存储比较复杂的数据类型. ...