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

499人阅读 评论(0)

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;

0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：174322次
• 积分：5468
• 等级：
• 排名：第5067名
• 原创：388篇
• 转载：0篇
• 译文：0篇
• 评论：47条
文章分类
最新评论