递归写法,好久不写很容易就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的更多相关文章

  1. 【题解】HDU5845 Best Division (trie树)

    [题解]HDU5845 Best Division (trie树) 题意:给定你一个序列(三个参数来根),然后请你划分子段.在每段子段长度小于等于\(L\)且子段的异或和\(\le x\)的情况下最大 ...

  2. python from __future__ import division

    1.在python2 中导入未来的支持的语言特征中division(精确除法),即from __future__ import division ,当我们在程序中没有导入该特征时,"/&qu ...

  3. [LeetCode] Evaluate Division 求除法表达式的值

    Equations are given in the format A / B = k, where A and B are variables represented as strings, and ...

  4. 关于分工的思考 (Thoughts on Division of Labor)

    Did you ever have the feeling that adding people doesn't help in software development? Did you ever ...

  5. POJ 3140 Contestants Division 树形DP

    Contestants Division   Description In the new ACM-ICPC Regional Contest, a special monitoring and su ...

  6. 暴力枚举 UVA 725 Division

    题目传送门 /* 暴力:对于每一个数都判断,是否数字全都使用过一遍 */ #include <cstdio> #include <iostream> #include < ...

  7. GDC2016【全境封锁(Tom Clancy's The Division)】对为何对应Eye Tracked System,以及各种优点的演讲报告

    GDC2016[全境封锁(Tom Clancy's The Division)]对为何对应Eye Tracked System,以及各种优点的演讲报告 原文 4Gamer編集部:松本隆一 http:/ ...

  8. Leetcode: Evaluate Division

    Equations are given in the format A / B = k, where A and B are variables represented as strings, and ...

  9. 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 ...

随机推荐

  1. Oracle将表keep到内存

    一.引言: 有时候一些基础表需要非常的频繁访问,尤其是在一些循环中,对该表中的访问速度将变的非常重要.为了提高系统的处理性能,可以考虑将一些表及索引读取并保存到内存中. 二.关于keep内存的几个参数 ...

  2. 实现Ecshop商品跳到淘宝、京东等的购买链接

    今天简单的实现了一下ecshop商品导出到第三方的购买链接功能.大致思路是给商品添加一个buy_link的text字段,存为json结构,然后通过json解析输出到商品购买页面 1.添加字段 增加购买 ...

  3. [BIM]STEP标准和EXPRESS语言

    参考:http://blog.sina.com.cn/s/blog_620be62e0100iqyb.html (BIM名词和术语(四)- IFC/STEP/EXPRESS) IFC标准使用形式化的数 ...

  4. HDU 4709:Herding

    Herding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Su ...

  5. YTU 3005: 皇后问题(栈和队列)

    3005: 皇后问题(栈和队列) 时间限制: 1 Sec  内存限制: 128 MB 提交: 6  解决: 3 题目描述 编写一个函数,求解皇后问题:在n*n的方格棋盘上,放置n个皇后,要求每个皇后不 ...

  6. java中@value的环境配置

    @value 在现阶段我想大家对注解都不陌生,@value的用法就是在后台获取配置文件的信息,从而方便修改一些固定的配置.不明白的可以百度@value的详解. 配置@value有以下几个步骤. 1.首 ...

  7. python 运行python manege.py runserver时报错:“no module named djangorestframework” 的解决方案

    python 运行python manege.py runserver时报错:“no module named djangorestframework” 的解决方案 importerror:no mo ...

  8. WebDriver使用指南(完整篇)

    第1章        入门 1.1   下载selenium2.0的lib包 http://code.google.com/p/selenium/downloads/list 官方UserGuide: ...

  9. userdebug版本开机串口log打开

    在/bootable/bootloader/lk/app/mt_boot/mt_boot.c里修改: if (!has_set_p2u) { #ifdef USER_BUILD sprintf(cmd ...

  10. AIM Tech Round 3 (Div. 2) B

    Description Vasya takes part in the orienteering competition. There are n checkpoints located along ...