[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() {st…
传送门 简单dp. 根据题目的描述. 如果数列bn{b_n}bn​合法. 那么有:bi−1b_{i-1}bi−1​&bi!=0b_i!=0bi​!=0,因此我们用f[i]f[i]f[i]表示数列b最后一位第i个二进制位为1的时候b数列的最长长度. 然后简单转移一下就行了. #include<bits/stdc++.h> #define N 100005 using namespace std; inline int read(){ int ans=0; char ch=getchar(…
bzoj4300绝世好题 题意: 给定一个长度为n的数列ai,求ai的子序列bi的最长长度,满足bi&bi-1!=0.n≤100000,ai≤10^9. 题解: 用f[i]表示当前二进制i为1的最长子序列长度.每次求所有((1<<i)&bi)==1的f[i]最大值max,将所有((1<<i)&bi)==1的f[i]变为max+1. 代码: #include <cstdio> #include <cstring> #include &l…
P4310 绝世好题 题目描述 给定一个长度为n的数列ai,求ai的子序列bi的最长长度,满足bi&bi-1!=0(2<=i<=len). 输入输出格式 输入格式: 输入文件共2行. 第一行包括一个整数n. 第二行包括n个整数,第i个整数表示ai. 输出格式: 输出文件共一行. 包括一个整数,表示子序列bi的最长长度. 输入输出样例 输入样例#1: 复制 3 1 2 3 输出样例#1: 复制 2 说明 对于100%的数据,1<=n<=100000,ai<=10^9.…
http://www.lydsy.com/JudgeOnline/problem.php?id=4300 f[i] 表示第i位&为1的最长长度 #include<cstdio> #include<iostream> #include<algorithm> using namespace std; void read(int &x) { x=; char c=getchar(); while(!isdigit(c)) c=getchar(); +c-';…
题意: n<=100000,ai<=2*10^9 思路:按二进制逐位考虑,只要有至少1位取and后为1就可以接下去 设dp[i]为第i位取and之后为1的最长的序列长度,意会一下 #include<cstdio> #include<iostream> typedef long long ll; using namespace std; #define MOD 1000000007 #define N 110000 ]; int main() { int n; scanf…
All Your Paths are Different Lengths 题目链接:https://atcoder.jp/contests/arc102/tasks/arc102_b 题解: 构造题有技巧,如果题目中要求了20和60,那就从这里入手好了. 发现没法入手因为太平凡了.... 但是,他要求了每种值只出现了一次,容易联想到弄出来$log$个$2$的幂次. 诶?想到这里发现,$20$好像差不多就是$log$大小. 我们就放$20$个点,第$i$个点指向第$i + 1$个点两条边,$2^{…
Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 1325  Solved: 722 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 O…
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 Solution $f[i]$表示二进制下看第$i…
设f[i][j]为前i个数中所选择的最后一个数在第j位上为1时的最长序列长度,转移显然. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; int read() { ,f=;char c=getchar(); ;c=getchar…