递归写法,好久不写很容易就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. IOS中两个view的切换

    在ios中,rootview为PassWordViewController,secondview为SecondViewController,实现在rootview中听过一个跳转按钮实现跳转到secon ...

  2. 最全面的Java多线程用法解析

    1.创建线程 在Java中创建线程有两种方法:使用Thread类和使用Runnable接口.在使用Runnable接口时需要建立一个Thread实例.因此,无论是通过Thread类还是Runnable ...

  3. Spring AOP:面向切面编程,AspectJ,是基于注解的方法

    面向切面编程的术语: 切面(Aspect): 横切关注点(跨越应用程序多个模块的功能)被模块化的特殊对象 通知(Advice): 切面必须要完成的工作 目标(Target): 被通知的对象 代理(Pr ...

  4. c#代码画图

    说明:此示例代码在我做的一个项目中  不过还是可以学习一下 一:直角坐标系显示数据 先看效果图:

  5. vs配置opencv

    配置OpenCv: 一.新建工程 无论是mfc还是控制台程序都可以. 二.下载opencb,安装在非空格路径下面 解压出来有两个文件夹:build和source,主要用到build,build-x86 ...

  6. 在C++工程中设置全局函数

    在头文件中对该函数进行全局函数的声明: extern void Test(); 在cpp文件中进行函数的定义: void Test() { MessageBox(NULL,L"调用了C++的 ...

  7. EXCEL中讲 10分10秒转换成610秒

    前几天宝贝跟我打赌100W说我20天给她打电话不到10小时,我说绝对超过10小时了,但是由于宝贝的赖皮死活不承认,所以我被迫掉出通话记录,拿到通话记录我有点小郁闷,因为通话记录里的时间格式00分00秒 ...

  8. 在Quartus II中分配管脚的两种常用方法

    在Quartus II中分配管脚的两种常用方法 示范程序 seg7_test.v 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 /* * ...

  9. BZOJ 2132 圈地计划(最小割)

    题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2132 题意:n*m的格子染色黑白,对于格子(i,j)染黑色则价值为A[i][j],白色为 ...

  10. C语言实现单向链表及其各种排序(含快排,选择,插入,冒泡)

    #include<stdio.h> #include<malloc.h> #define LEN sizeof(struct Student) struct Student / ...