a + b == a & b + a | b,所以已知bi,ci,那么定義di = (ai-1 & ai) = ci - bi
已知a1即可確定整個a序列,因此判斷a1的取值有多少種可能即代表a序列有多少種可能。
#include<iostream>#include<algorithm>#include<cmath>#include<cstring>#include<vector>#include<unordered_map>#include<unordered_set>#include<set>#defineendl'\n'#defineIOSios::sync_with_stdio(false); cin.tie(0); cout.tie(0)usingnamespace std;typedeflonglong ll;constint N =1e5+10;int b[N], c[N];int n;// x表示當前這一位是0還是1intdfs(int pos,int x){for(int i =2; i <= n; i ++){int p =(b[i]>> pos &1), q =(c[i]>> pos &1);if(x && p && q) x =1;elseif(!x && p && q)return0;elseif(x && p &&!q) x =0;// 交替elseif(!x && p &&!q) x =1;// 交替elseif(x &&!p && q)return0;elseif(!x &&!p && q)return0;elseif(x &&!p &&!q)return0;elseif(!x &&!p &&!q) x =0;}return1;}intmain(){IOS;cin >> n;for(int i =2; i <= n; i ++) cin >> b[i];for(int i =2; i <= n; i ++) cin >> c[i], c[i]-= b[i];for(int i =2; i <= n; i ++)if(c[i]<0){cout <<0<< endl;return0;}ll ans =1;for(int i =0; i <31; i ++){int x =dfs(i,0), y =dfs(i,1);ans *=(x + y);}cout << ans << endl;return0;}與50位技術(shù)專家面對面20年技術(shù)見證,附贈技術(shù)全景圖