The problem was solved by DP at the beginning, but it was wrong to think about it, because such bit operations could not obtain the optimal solution until the last computation, that is, there was no optimal sub-structure.
First, when a and B perform operations, we analyze every bit on the 64-bit. We know that the & and ^ operations always generate 0, so we can always make the 32-bit value equal to 0 for the two 64-bit numbers. If we calculate the number X and C, we will directly convert X & C, those bits whose values are already 0 will definitely remain 0, and the remaining bits are not 0 or 1. If the result contains more than 1, we will reverse C, if at least half of the total number is 0, then the number is more than six. If the number is less than 0, we are directly violent.
The Code is as follows:
#include <cstdlib>#include <cstring>#include <cstdio>#include <algorithm>using namespace std;typedef unsigned long long int Int64;int N;Int64 seq[10], ret;void dfs(Int64 statu, int deep){ if (deep == N) { ret = min(statu, ret); return; } if (deep == 0) { dfs(seq[deep+1], deep+1); dfs(~seq[deep+1], deep+1); } else { dfs(statu & seq[deep+1], deep+1); dfs(statu | seq[deep+1], deep+1); dfs(statu ^ seq[deep+1], deep+1); dfs(statu & (~seq[deep+1]), deep+1); dfs(statu | (~seq[deep+1]), deep+1); dfs(statu ^ (~seq[deep+1]), deep+1); }}int main(){ int T, ca = 0; Int64 x; scanf("%d", &T); while (T--) { scanf("%d", &N); if (N > 6) { for (int i = 0; i < N; ++i) { scanf("%I64u", &x); } printf("Case #%d: %I64u\n", ++ca, 0LLU); continue; } ret = 1LLU<<63; for (int i = 1; i <= N; ++i) { scanf("%I64u", &seq[i]); } dfs(0, 0); printf("Case #%d: %I64u\n", ++ca, ret); } return 0; }