递归写法,好久不写很容易就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. vlc分析

    vlc的主界面对应的代码在vlc-2.2.1\modules\gui\qt4\main_interface.cpp.在相同目录下的qt4.cpp的module模块open函数里边new出实例: /* ...

  2. PHP中Array关于数组的用法

    使用函数array_keys(),得到数组中所有的键,参数:数组 $arr=array();$arr['one']="one";$arr['two']="two" ...

  3. 【PHP设计模式 01_DuoTai.php】多态的说明

    <?php /** * [多态] * 定义一个抽象类:Tiger,有两个子类:XTiger 和 MTiger */ header("Content-type: text/html; c ...

  4. 25、oracle(一)

    1)了解oracle背景,概念和特点 2)掌握oracleSQL对单表各种查询操作 3)掌握oracleSQL中函数的使用 4)掌握数值型number,字符串型varchar2,日期型date,条件判 ...

  5. http://www.cnblogs.com/xqin/p/4862849.html

    一.前言 半年前左右折腾了一个前后端分离的架子,这几天才想起来翻出来分享给大家.关于前后端分离这个话题大家也谈了很久了,希望我这个实践能对大家有点点帮助,演示和源码都贴在后面. 二.技术架构 这两年a ...

  6. Chrome开发者工具学习

    Chrome开发者工具分为8个大模块,每个模块功能为: 1.Element标签页:用于查看和编辑当前页面中的HTML和CSS元素. 左侧可以看到页面的源码,HTML和CSS元素,双击可以进行修改.右侧 ...

  7. Oracle绑定变量

    select * from table where id = ? 类似于上面这样的sql,如果不用绑定变量,每次执行时Oracle会认为是不同的sql,会在每次执行时生成一遍执行计划,而执行计划的生成 ...

  8. 字符编码的过滤器Filter(即输入的汉字,能在页面上正常显示,不会出现乱码)

    自定义抽象的 HttpFilter类, 实现自 Filter 接口 package com.lanqiao.javaweb; import java.io.IOException; import ja ...

  9. 周赛-Expression 分类: 比赛 2015-08-02 09:35 3人阅读 评论(0) 收藏

    A. Expression time limit per test1 second memory limit per test256 megabytes inputstandard input out ...

  10. [转]get,post数据长度的限制

    一.问题起因 在某项目释放后Bug统计的附件<释放后问题>里有: 问题 原因 分析 备注 CSV处理时,如果处理的主题数过多,发生URL参数上限的错误: 可变长度的参数通过URL方式传递, ...