感受
思路
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 5e3 + 10; ll f[maxn][maxn]; ll dp[maxn][maxn]; ll a[maxn]; int n; int main(){ scanf("%d", &n); for(int i = 1; i <= n; i++){ scanf("%lld", &a[i]); dp[i][i] = f[i][i] = a[i]; } for(int len = 2; len <= n; len++){ for(int l = 1, r;; l++){ r = l+ len - 1; if(r > n) break; dp[l][r] = f[l][r] = f[l][r - 1] ^ f[l + 1][r]; dp[l][r] = max(dp[l][r], dp[l][r - 1]); dp[l][r] = max(dp[l][r], dp[l + 1][r]); } } int q, l, r; scanf("%d", &q); while(q--){ scanf("%d%d", &l, &r); printf("%lld\n", dp[l][r]); } return 0; }