[bzoj4300]绝世好题_二进制拆分
绝世好题 bzoj-4300
题目大意:题目链接。
注释:略。
想法:
二进制拆分然后用一个数组单独存一下当前答案即可。
Code:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 100010
using namespace std;
int a[N],p[32],f[N],mx[32];
inline char nc() {static char *p1,*p2,buf[100000]; return (p1==p2)&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;}
int rd() {int x=0; char c=nc(); while(!isdigit(c)) c=nc(); while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=nc(); return x;}
int main()
{
int n=rd(); for(int i=1;i<=n;i++) a[i]=rd();
p[0]=1; for(int i=1;i<=31;i++) p[i]=p[i-1]<<1;
for(int i=1;i<=n;i++)
{
int now=0;
for(int j=0;j<=30;j++) if(a[i]&p[j])
{
now=max(now,mx[j]);
}
f[i]=now+1;
for(int j=0;j<=30;j++) if(a[i]&p[j]) mx[j]=max(mx[j],f[i]);
}
int ans=0; for(int i=1;i<=n;i++) ans=max(ans,f[i]);
cout << ans << endl ;
return 0;
}
小结:无。
[bzoj4300]绝世好题_二进制拆分的更多相关文章
- 2018.09.27 bzoj4300: 绝世好题(二进制dp)
传送门 简单dp. 根据题目的描述. 如果数列bn{b_n}bn合法. 那么有:bi−1b_{i-1}bi−1&bi!=0b_i!=0bi!=0,因此我们用f[i]f[i]f[i]表示数 ...
- bzoj4300绝世好题
bzoj4300绝世好题 题意: 给定一个长度为n的数列ai,求ai的子序列bi的最长长度,满足bi&bi-1!=0.n≤100000,ai≤10^9. 题解: 用f[i]表示当前二进制i为1 ...
- 【洛谷】4310: 绝世好题【二进制DP】
P4310 绝世好题 题目描述 给定一个长度为n的数列ai,求ai的子序列bi的最长长度,满足bi&bi-1!=0(2<=i<=len). 输入输出格式 输入格式: 输入文件共2行 ...
- bzoj千题计划190:bzoj4300: 绝世好题
http://www.lydsy.com/JudgeOnline/problem.php?id=4300 f[i] 表示第i位&为1的最长长度 #include<cstdio> # ...
- 【BZOJ4300】绝世好题(二进制,DP)
题意: n<=100000,ai<=2*10^9 思路:按二进制逐位考虑,只要有至少1位取and后为1就可以接下去 设dp[i]为第i位取and之后为1的最长的序列长度,意会一下 #inc ...
- [Arc102B]All Your Paths are Different Lengths_构造_二进制拆分
All Your Paths are Different Lengths 题目链接:https://atcoder.jp/contests/arc102/tasks/arc102_b 题解: 构造题有 ...
- Bzoj4300 绝世好题
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 1325 Solved: 722 Description 给定一个长度为n的数列ai,求ai的子序列bi ...
- BZOJ4300:绝世好题(DP)
Description 给定一个长度为n的数列ai,求ai的子序列bi的最长长度,满足bi&bi-1!=0(2<=i<=len). Input 输入文件共2行. 第一行包括一个整数 ...
- BZOJ4300 绝世好题(动态规划)
设f[i][j]为前i个数中所选择的最后一个数在第j位上为1时的最长序列长度,转移显然. #include<iostream> #include<cstdio> #includ ...
随机推荐
- 移动端rem
手机有很多尺寸的型号.使用rem来做为大小单位可以达到兼容的目的. 方法一:js测量手机尺寸,设置font-size:为手机屏幕width /10 + ‘px’.即10rem 为手机屏幕width. ...
- kalman滤波器公式的推导
卡尔曼滤波的使用范围: 该系统要有如下关系: 计算步骤: PART0:INI PART1:Time update 迭代的目标:从X(K-1)+ 求得X(K) + 因此,先有X(K-1)+,已知F,G. ...
- 【数据分析 R语言实战】学习笔记 第三章 数据预处理 (下)
3.3缺失值处理 R中缺失值以NA表示,判断数据是否存在缺失值的函数有两个,最基本的函数是is.na()它可以应用于向量.数据框等多种对象,返回逻辑值. > attach(data) The f ...
- SOA测试之浏览器插件
1. Chrome HTTP Rest Client 插件: 1.1 Postman: https://chrome.google.com/webstore/detail/postman-rest-c ...
- 使用Jenkins进行android项目的自动构建(2)
Maven and POM 1. 什么是Maven? 官方的解释是: http://maven.apache.org/guides/getting-started/index.html#What_is ...
- Farseer.net轻量级ORM开源框架说明及链接索引
项目简介 基于.net framework 4 开发. 基于Lambda表达式快速上手的ORM框架. 参考Entity Framework的调用方式. 基于Database First模式. POCO ...
- ansys中的.full文件中如何看刚度矩阵和质量矩阵(转)
http://fffff-2001.blog.163.com/blog/static/15507529200722492917460 Q:请问ansys中的.full文件中如何看刚度矩阵和质量矩阵? ...
- PowerDesigner 操作手册
1.错误信息:Generation aborted due to errors detected during the verification of the model 解决方案: 把检查模型的选项 ...
- 类方法__setattr__,__delattr__,__getattr__
__getattr__,_delattr_,_getattr_ class Foo: x = 1 def __init__(self, y): self.y = y def __getattr__(s ...
- tensorflow ConfigProto
tf.ConfigProto一般用在创建session的时候.用来对session进行参数配置 with tf.Session(config = tf.ConfigProto(...),...)#tf ...