# HDU 5715 & 2016"百度之星" 复赛（Astar Round3）1004 XOR游戏(Trie)

dp[i][j]$dp[i][j]$表示将前i个数据分为j组后最小值是否大于等于t

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <set>
#include <ctime>
#define eps 1e-6
#define LL long long
#define pii pair<int, int>
using namespace std;
const int mod = 1e9+9;
const int maxnode = 500000;
const int N = 30;

int n, m, len;
int a[10010], s[10010];
bool dp[10010][12];
struct Trie {
int ch[maxnode][2];
int val[maxnode];
int sz;
void clear() {
ch[0][0] = ch[0][1] = 0;
sz = 1;
}
void add(int num, int v) {
int u = 0;
for (int i = N; i >= 0; i--) {
int c = (num>>i)&1;
if (!ch[u][c]) {
ch[sz][0] = ch[sz][1] = 0;
val[sz] = 0;
ch[u][c] = sz++;
}
u = ch[u][c];
val[u] += v;
}
}
bool find(int num, int b) {
int sum = 0, u = 0;
for (int i = N; i >= 0; i--) {
int c = (num>>i)&1;
if (sum+(1<<i) >= b) {
if (ch[u][c^1] && val[ch[u][c^1]] > 0)
return true;
u = ch[u][c];
if (!u) return false;
}
else {
sum += 1<<i;
u = ch[u][c^1];
if (!u) return false;
}
}
return (sum >= b && val[u] > 0);
}
} t[12];
bool check(int b) {
for (int i = 1; i < m; i++)
t[i].clear();
for (int i = 1; i <= n; i++)
dp[i][1] = (s[i]>=b) && (i<=len);
for (int i = 1; i <= n; i++) {
if (i > 1 && dp[i-1][1])
for (int j = 2; j <= m && j <= i; j++) {
if (i > len+1 && dp[i-len-1][j-1])
dp[i][j] = t[j-1].find(s[i], b);
//cout << i << " " << j << " " << dp[i][j] << endl;
if (dp[i][j])
}
}
return dp[n][m];
}
int main()
{
//freopen("input.txt", "r", stdin);
int T;
cin >> T;
int kase = 0;
s[0] = 0;
while (T--) {
scanf("%d%d%d", &n, &m, &len);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
for (int i = 1; i <= n; i++)
s[i] = s[i-1] ^ a[i];
int l = 0, r = 1e9;
check(7);
while (l <= r) {
int mid = (l+r) >> 1;
if (check(mid)) l = mid + 1;
else r = mid - 1;
}
printf("Case #%d:\n%d\n", ++kase, r);
}
return 0;


#### 2016"百度之星"-初赛（AstarRound2A）解题报告

2016-08-24 18:17:15

#### 2016百度之星初赛Astar Round2B - 区间的价值

2016-05-23 09:58:25

#### 2016"百度之星" - 初赛（Astar Round2A）题解

2016-05-21 20:22:40

#### 2017百度之星 复赛

2017-08-18 21:36:12

#### 2016"百度之星" - 复赛（Astar Round3）1003 1004

2016-06-06 21:17:35

#### HDU-2017"百度之星"程序设计大赛-复赛-1003-Pokémon GO

2017-08-18 16:47:38

#### hdu 5715 XOR 游戏(trie)

2016-05-29 22:52:37

#### HDU 6172 and HDU 6185 【线性递推 + 思维 + 板子】

2017-09-03 13:14:19

#### 【TEST】2017百度之星程序设计大赛 - 复赛

2017-09-02 10:14:25

#### hdu 4825 Xor Sum(字典树)

2014-05-21 23:20:19