HDU5845 Best Division
递归写法,好久不写很容易就gg了...
dp[i]=max(dp[j])+1,并且s[i]XORs[j]<=x
01字典树优化一下转移。
#include <bits/stdc++.h> #define ll long long
#define ull unsigned long long
#define st first
#define nd second
#define pii pair<int, int>
#define pil pair<int, ll>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define tiii tuple<int, int, int>
#define pw(x) ((1LL)<<(x))
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define FIN freopen("A.in","r",stdin);
#define FOUT freopen("A.out","w",stdout);
using namespace std;
/***********/
template <class T>
bool scan (T &ret) {
char c;
int sgn;
if (c = getchar(), c == EOF) return ; //EOF
while (c != '-' && (c < '' || c > '') ) c = getchar();
sgn = (c == '-') ? - : ;
ret = (c == '-') ? : (c - '');
while (c = getchar(), c >= '' && c <= '') ret = ret * + (c - '');
ret *= sgn;
return ;
}
template<typename N,typename PN>inline N flo(N a,PN b){return a>=?a/b:-((-a-)/b)-;}
template<typename N,typename PN>inline N cei(N a,PN b){return a>?(a-)/b+:-(-a/b);}
template<typename T>inline int sgn(T a) {return a>?:(a<?-:);}
template <class T1, class T2>
bool gmax(T1 &a, const T2 &b) { return a < b? a = b, :;}
template <class T1, class T2>
bool gmin(T1 &a, const T2 &b) { return a > b? a = b, :;}
template <class T> inline T lowbit(T x) {return x&(-x);} template<class T1, class T2>
ostream& operator <<(ostream &out, pair<T1, T2> p) {
return out << "(" << p.st << ", " << p.nd << ")";
}
template<class A, class B, class C>
ostream& operator <<(ostream &out, tuple<A, B, C> t) {
return out << "(" << get<>(t) << ", " << get<>(t) << ", " << get<>(t) << ")";
}
template<class T>
ostream& operator <<(ostream &out, vector<T> vec) {
out << "("; for(auto &x: vec) out << x << ", "; return out << ")";
}
void testTle(int &a){
while() a = a*(long long)a%;
}
const int inf = 0x3f3f3f3f;
const long long INF = 1e17;
const long long mod = ;
const double eps = 1e-;
const int N = 1e5+;
/***********/ int a[N], X;
struct Tire{
int tot, node[N][], val[N], dp[N];
int newnode(){
++tot;
node[tot][] = node[tot][] = val[tot] = ;
dp[tot] = -1e9;
return tot;
}
void init(){
tot = ;
newnode();
}
void pushup(int rt){
val[rt] = ;
dp[rt] = -1e9;
if(node[rt][]&&val[ node[rt][] ]) {
gmax(dp[rt], dp[ node[rt][] ]);
val[rt] += val[ node[rt][] ];
}
if(node[rt][]&&val[ node[rt][] ]) {
gmax(dp[rt], dp[ node[rt][] ]);
val[rt] += val[ node[rt][] ];
}
}
void update(int x, int d, int v, int now = , int dep = ){
if(dep == -){
val[now] += d;
if(val[now]) gmax(dp[now], v);
else dp[now] = -1e9;
return ;
}
int t = &(x>>dep);
if(!node[now][t]) node[now][t] = newnode();
update(x, d, v, node[now][t], dep-);
pushup(now);
}
int query(int x, int now = , int dep = ){
if(dep == -) return dp[now];
int t1 = &(X>>dep), t2 = &(x>>dep);
int ret = -1e9;
if(t1){
if(node[now][t2]) gmax(ret, dp[ node[now][t2] ]);
if(node[now][t2^]) gmax(ret, query(x, node[now][t2^], dep-));
}
else if(node[now][t2]) gmax(ret, query(x, node[now][t2], dep-));
return ret;
}
}T;
int f[N];
int main(){
int t; scanf("%d", &t);
while(t--){
int n, L, p, q, i;
scanf("%d%d%d", &n, &X, &L);
scanf("%d%d%d", a+, &p, &q);
for(i = ; i <= n; i++)
a[i] = (a[i-]*(ll)p+q)%268435456LL;
for(int i = ; i <= n; i++)
a[i] = a[i]^a[i-];
T.init();
T.update(a[], , f[]);
for(i = ; i <= n&&i <= L; i++){
f[i] = T.query(a[i])+;
T.update(a[i], , f[i]);
} for( ; i <= n; i++){
T.update(a[i-L-], -, f[i-L-]);
f[i] = T.query(a[i])+;
T.update(a[i], , f[i]);
}
printf("%d\n", max(f[n], ));
}
return ;
}
HDU5845 Best Division的更多相关文章
- 【题解】HDU5845 Best Division (trie树)
[题解]HDU5845 Best Division (trie树) 题意:给定你一个序列(三个参数来根),然后请你划分子段.在每段子段长度小于等于\(L\)且子段的异或和\(\le x\)的情况下最大 ...
- python from __future__ import division
1.在python2 中导入未来的支持的语言特征中division(精确除法),即from __future__ import division ,当我们在程序中没有导入该特征时,"/&qu ...
- [LeetCode] Evaluate Division 求除法表达式的值
Equations are given in the format A / B = k, where A and B are variables represented as strings, and ...
- 关于分工的思考 (Thoughts on Division of Labor)
Did you ever have the feeling that adding people doesn't help in software development? Did you ever ...
- POJ 3140 Contestants Division 树形DP
Contestants Division Description In the new ACM-ICPC Regional Contest, a special monitoring and su ...
- 暴力枚举 UVA 725 Division
题目传送门 /* 暴力:对于每一个数都判断,是否数字全都使用过一遍 */ #include <cstdio> #include <iostream> #include < ...
- GDC2016【全境封锁(Tom Clancy's The Division)】对为何对应Eye Tracked System,以及各种优点的演讲报告
GDC2016[全境封锁(Tom Clancy's The Division)]对为何对应Eye Tracked System,以及各种优点的演讲报告 原文 4Gamer編集部:松本隆一 http:/ ...
- Leetcode: Evaluate Division
Equations are given in the format A / B = k, where A and B are variables represented as strings, and ...
- hdu 1034 (preprocess optimization, property of division to avoid if, decreasing order process) 分类: hdoj 2015-06-16 13:32 39人阅读 评论(0) 收藏
IMO, version 1 better than version 2, version 2 better than version 3. make some preprocess to make ...
随机推荐
- 启动hadoop报192.168.1.151: Address 192.168.1.151 maps to node1, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
使用root用户启动hadoop的时候报错: [root@node1 ~]# su - hadoop -c start-all.sh starting namenode, logging to /ap ...
- PHP程序中删除字符串最后一个字符的三种方法
常见的语法格式: foreach ($arr as $key => $value) {$arr_str = $arr['x_id'] . ',' . $arr_str;} 假设字符数组 $arr ...
- Oracle触发器使用介绍
触发器,函数,包都是可以再生利用的东西,所以在创建的时候都要用到create or replace这个万能语句,接着就是主角trigger的出现了,主角出现还需要一点点波动,通常大人物都不是随随便便就 ...
- hdwiki 编码规范
编码规范 命名规范 1.1.主要的目录 control 里面是控制类 ,前台命名为something.php,则后台对应的是admin_+前台名称,名称应选有意义的英文单词,例如 前台 ...
- c3p0数据库连接池(作用不重复)
/* * c3p0数据库连接池: * 只被初始化一次 * connection对象进行close时,不是正的关闭,而是将该数据连接归还给数据库连接池 * * */ 四个架包 mysql-connect ...
- Uva 11754 Code Feat
题意概述: 有一个正整数$N$满足$C$个条件,每个条件都形如“它除以$X$的余数在集合$\{Y_1, Y_2, ..., Y_k\}$中”,所有条件中的$X$两两互质, 你的任务是找出最小的S个解. ...
- FZU 2105 Digits Count(线段树)
Problem 2105 Digits Count Accept: 302 Submit: 1477 Time Limit: 10000 mSec Memory Limit : 262144 KB P ...
- C#中容易被忽视的细节整理
(有空更新系列) 1.params可变长度参数,默认值是长度为0的数组,而不是空 2.事件和委托默认值都是null 3.bool返回值的事件调用之后,其内部的合并方式是取最后一个合并对象的返回值
- #ifdef __cplusplus extern "C" { #endif
1.在好多程序中我们会遇到下面代码段 #ifdef __cplusplus extern "C" { #endif //c语法代码段 #ifdef __ ...
- 2016年10月20日 星期四 --出埃及记 Exodus 19:4
2016年10月20日 星期四 --出埃及记 Exodus 19:4 `You yourselves have seen what I did to Egypt, and how I carried ...