hdu 5536 Chip Factory (01 Trie)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536
题面;
SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。Chip Factory
Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 6277 Accepted Submission(s): 2847
At the end of the day, he packages all the chips produced this day, and send it to wholesalers. More specially, he writes a checksum number on the package, this checksum is defined as below:
max
which i,j,k
Can you help John calculate the checksum number of today?
Input The first line of input contains an integer T
The first line of each test case is an integer n
1≤T≤1000
3≤n≤1000
0≤s
There are at most 10
Output For each test case, please output an integer indicating the checksum number in a line.
Sample Input 2 3 1 2 3 3 100 200 300
Sample Output 6 400
模板题
Source 2015ACM/ICPC亚洲区长春站-重现赛(感谢东北师大) 实现代码;#include<bits/stdc++.h> using namespace std; #define ll long long const int M = 1e3+10; int tot; int ch[32*M][2],vis[32*M]; ll val[32*M],a[M]; void init(){ memset(vis,0,sizeof(vis)); tot = 1; ch[0][0] = ch[0][1] = 0; } void ins(ll x){ int u = 0; for(int i = 32;i >= 0;i --){ int v = (x>>i)&1; if(!ch[u][v]){ ch[tot][0] = ch[tot][1] = 0; val[tot] = 0; vis[tot] = 0; ch[u][v] = tot++; } u = ch[u][v]; vis[u]++; } val[u] = x; } void update(ll x,int c){ int u = 0; for(int i = 32;i >= 0;i --){ int v = (x>>i)&1; u = ch[u][v]; vis[u] += c; } } ll query(ll x){ int u = 0; for(int i = 32;i >= 0;i --){ int v = (x>>i)&1; if(ch[u][v^1]&&vis[ch[u][v^1]]) u = ch[u][v^1]; else u = ch[u][v]; } return x^val[u]; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t,n,m; cin>>t; while(t--){ cin>>n; ll mx = 0; init(); for(int i = 1;i <= n;i ++) cin>>a[i],ins(a[i]); for(int i = 1;i <= n;i ++){ for(int j = i+1;j <= n;j ++){ update(a[i],-1); update(a[j],-1); mx = max(mx,query(a[i]+a[j])); update(a[i],1); update(a[j],1); } } cout<<mx<<endl; } }

更多精彩