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 ...
随机推荐
- jstl和jsp脚本变量相互访问
1.jsp脚本访问jstl标准动作的变量,可以通过隐式的范围变量来获取,对于页面作用域的变量,可以通过pageContext.getAttribute()来获取,也可以通过动作来获取: <c:s ...
- python怎么装模块
windows下 最简单的方法: File---Settings--Project ---Project Interpreter 下----点击 +号,输入你需要安装的模块名,点击Install P ...
- YTU 2344: 先序遍历二叉树
原文链接:https://www.dreamwings.cn/ytu2344/2603.html 2344: 先序遍历二叉树 时间限制: 1 Sec 内存限制: 128 MB 提交: 4 解决: ...
- HDU 自动刷题机 Auto AC (轻轻松松进入HDU首页)
前言: 在写这篇文章之前,首先感谢给我思路以及帮助过我的学长们 以下4篇博客都是学长原创,其中有很多有用的,值得学习的东西,希望能够帮到大家! 1.手把手教你用C++ 写ACM自动刷题神器(冲入HDU ...
- javaWEB国际化:DateFormat,NumberFormat,MessageFormat,ResourceBundle的使用
DateFormat:格式化日期的工具类,本身是一个抽象类: NumberFormat:格式化 数字 到 数字字符串,或货币字符串的字符类; MessageFormat: 可以格式化模式字符串,模式字 ...
- Maya Calendar 分类: POJ 2015-06-11 21:44 12人阅读 评论(0) 收藏
Maya Calendar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 70016 Accepted: 21547 D ...
- U3D UGUI学习5 - Layout和文字适配
Layout这部分UGUI算是比NGUI做的到位 之前遇到了一个问题,NGUI做文字和背景框适配和容易,绑定一下就好了.UGUI你得弄Layout才可以,而且还需要配置. 但这个Layout使用场合是 ...
- PostgreSql安装
官网:http://www.postgresql.org/download/linux/redhat/ 一.安装 由于我的机子是centos6.2,所以选择RedHat的. 按照官网所说的进行安装: ...
- spring Aop中aop:advisor 与 aop:aspect的区别
转载:http://blog.csdn.net/u011710466/article/details/52888277 在spring的配置中,会用到这两个标签.那么他们的区别是什么呢? ...
- SQL Server中常用的SQL语句
1.概述 名词 笛卡尔积.主键.外键 数据完整性 实体完整性:主属性不能为空值,例如选课表中学号和课程号不能为空 参照完整性:表中的外键取值为空或参照表中的主键 用户定义完整性:取值范围或非空限制,例 ...