Explanation
To solve this problem, notice that the result of performing XOR operations on a sequence of is strictly less than . That's because the ninth bit is the largest possible in the binary representation of .
With this observation, we can now formulate our DP solution. Let represent the feasibility of getting as a result of XOR of an increasing sequence ending with a number less than or equal to . There exists the following recurrence:
with
since it is always possible to get 0 from an increasing sequence consisting of zero element.
Implementation
Time Complexity:
C++
#include <bits/stdc++.h>using namespace std;const int MAXA = 1 << 9;int main() {int n;cin >> n;vector<int> arr(n);for (int &i : arr) { cin >> i; }
Join the USACO Forum!
Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!