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

4300: 绝世好题 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/problem.php?id=4300 Description 给定一个长度为n的数列ai,求ai的子序列bi的最长长度,满足bi&bi-1!=0(2<=i<=len). Under two situations the player could score one point. ⋅1. If you touc…
题目: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<alg…
HYSBZ(BZOJ) 4300 绝世好题(位运算,递推) 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 Http HYSBZ:http://www.lydsy…
4300: 绝世好题 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=4300 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 Sam…
4300: 绝世好题 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 564  Solved: 289[Submit][Status][Discuss] Description 给定一个长度为n的数列ai,求ai的子序列bi的最长长度,满足bi&bi-1!=0(2<=i<=len). Input 输入文件共2行. 第一行包括一个整数n. 第二行包括n个整数,第i个整数表示ai. Output 输出文件共一行. 包括一个整数,表示子序列bi的…
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…
设f[i][j]表示数列到i为止最后一项第j位为1的最大子序列长度,每次从i-1中1<<j&a[i]!=0的位+1转移来 然后i维是不需要的,答案直接在dp过程中去max即可 #include<iostream> #include<cstdio> using namespace std; int n,f[35],ans; int read() { int r=0,f=1; char p=getchar(); while(p>'9'||p<'0') {…
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=4300 [题目大意] 给出一个序列a,求一个子序列b,使得&和不为0 [题解] 记录某个位置上为1的&序列长度的最长值,对于每个加入的数字, 更新每个数组. __builtin_ctz(x)函数用于求出x的二进制位数. [代码] #include <cstdio> #include <algorithm> int x,ans,res,n,a[40]; us…
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4300 记录一下 mx[j] 表示以第 j 位上是1的元素结尾的子序列长度最大值,转移即可. 代码如下: #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ,xm=; int n,a[xn],mx[xm],bin[x…
对于每一个数字拆位,然后维护一个大小为 30 左右的桶即可. code: #include <bits/stdc++.h> #define N 100006 #define setIO(s) freopen(s".in","r",stdin) using namespace std; int mx[N]; int main() { // setIO("input"); int i,j,n,ans=0; scanf("%d&q…