【54.38%】【BZOJ 4300】绝世好题
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 1120 Solved: 609
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
1 2 3
Sample Output
HINT
n<=100000,ai<=2*10^9
Source
【题解】
设f[i],二进制中倒数第i位为1的数(其他位置不一定)所形成的数列的最长长度;
【代码】
#include <cstdio>
#include <algorithm> using namespace std; const int MAXN = 101000; int n,ans = 0;
int x;
int f[31] = { 0 }; int main()
{
scanf("%d", &n);
for (int i = 1; i <= n; i++)
{
scanf("%d", &x);
int temp = 0;
for (int j = 0; j <= 30; j++)
if (x & (1 << j))
temp = max(temp, f[j] + 1);
for (int j = 0; j <= 30; j++)
if (x & (1 << j))
f[j] = temp;
ans = max(ans, temp);
}
printf("%d\n", ans);
return 0;
}
【54.38%】【BZOJ 4300】绝世好题的更多相关文章
- HYSBZ(BZOJ) 4300 绝世好题(位运算,递推)
HYSBZ(BZOJ) 4300 绝世好题(位运算,递推) Description 给定一个长度为n的数列ai,求ai的子序列bi的最长长度,满足bi&bi-1!=0(2<=i<= ...
- bzoj 4300: 绝世好题
4300: 绝世好题 Time Limit: 1 Sec Memory Limit: 128 MB Description 给定一个长度为n的数列ai,求ai的子序列bi的最长长度,满足bi& ...
- BZOJ 4300: 绝世好题 动态规划
4300: 绝世好题 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=4300 Description 给定一个长度为n的数列ai,求ai的 ...
- 【递推】BZOJ 4300:绝世好题
4300: 绝世好题 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 564 Solved: 289[Submit][Status][Discuss] ...
- bzoj 4300: 绝世好题 dp
4300: 绝世好题 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/problem.php ...
- BZOJ 4300 绝世好题(位运算)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=4300 [题目大意] 给出一个序列a,求一个子序列b,使得&和不为0 [题解] ...
- bzoj 4300 绝世好题——DP
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4300 考虑 dp[ i ] 能从哪些 j 转移过来,就是那些 a[ j ] & a[ ...
- bzoj 4300 绝世好题 —— 思路
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4300 记录一下 mx[j] 表示以第 j 位上是1的元素结尾的子序列长度最大值,转移即可. ...
- bzoj 4300: 绝世好题【dp】
设f[i][j]表示数列到i为止最后一项第j位为1的最大子序列长度,每次从i-1中1<<j&a[i]!=0的位+1转移来 然后i维是不需要的,答案直接在dp过程中去max即可 #i ...
- BZOJ 4300: 绝世好题 二进制
对于每一个数字拆位,然后维护一个大小为 30 左右的桶即可. code: #include <bits/stdc++.h> #define N 100006 #define setIO(s ...
随机推荐
- TypeScript深入学习
基础类型booleannumberstringstring[]//Array<string> 数组类型(ReadonlyArray<string>数组不能修改,也不允许被赋值给 ...
- iOS多语言(国际化)开发(尾随系统 + APP内手动设置)
一:尾随系统切换语言 1>创建好项目project后, 新建一个多语言文件: 2>加入要设置的语言类型: 3>加入成功 细心的朋友可能会发如今English后面写的是3 Files ...
- ontouch-控件添加ontouch监听事件
1,代码public class CalculatorViewPager extends ViewPager {}中 package com.android.calculator2; import a ...
- git仓库搭建
第一步安装git [root@Centos-node2 ~]# yum -y install git 第二步创建git用户 [root@Centos-node2 ~]# useradd git [ro ...
- Android Notification.setLatestEventInfo弃用和Notification.Builder用法
今天在学习小米便签的源码的时候,至于源码的地址,http://m.blog.csdn.net/article/details?id=50544248 ,里面有好多github的开源项目,打开项目,报错 ...
- GO语言学习(十三)Go 语言变量作用域
Go 语言变量作用域 作用域为已声明标识符所表示的常量.类型.变量.函数或包在源代码中的作用范围. Go 语言中变量可以在三个地方声明: 函数内定义的变量称为局部变量 函数外定义的变量称为全局变量 函 ...
- Codeforces_GYM_100741 A
http://codeforces.com/gym/100741/problem/A A. Queries time limit per test 0.25 seconds memory limit ...
- 机房收费 & 廊院食堂
做机房收费系统时.常常想这个一般用户指的是谁?我当初以为是学生......可能是被数据库中的student带跑偏了...... 事实上把我们的系统联系一下实际,就会非常easy想到一般用户指的是谁的位 ...
- maven插件介绍之tomcat7-maven-plugin
tomcat7-maven-plugin插件的pom.xml依赖为: <dependency> <groupId>org.apache.tomcat.maven</gro ...
- Garbage Collection Optimization for High-Throughput and Low-Latency Java Applications--转载
原文地址:https://engineering.linkedin.com/garbage-collection/garbage-collection-optimization-high-throug ...