[TIOJ] 1094. C.幼稚國王的獎賞
題目連結: http://tioj.infor.org/problems/1094 這題有三種作法,一種是我看完馬上想到的砍半枚舉後套trie #include <bits/stdc++.h>
using namespace std;
const int LOG_C = 20;
const int N = 30 + 5;
inline int two(int x){return 1<<x;}
class Trie{
private:
static constexpr int MEM = 5000000;
struct node{
int lc, rc;
node(): lc(0), rc(0){}
} nodes[MEM];
int mem_, root;
inline int new_node(){
assert(mem_ < MEM);
nodes[mem_] = node();
return mem_++;
}
void insert(int x, int& cur, int d){
if(!cur) cur = new_node();
if(d == -1) return;
if(x & two(d)) insert(x, nodes[cur].rc, d-1);
else insert(x, nodes[cur].lc, d-1);
}
int query(int x, int cur, int d){
if(d == -1) return 0;
if(x & two(...