标签:clu 区间dp name bsp ons c++ ace 思路 out
思路:
简单的区间dp。
实现:
1 #include <bits/stdc++.h> 2 using namespace std; 3 const int MAXN = 5005; 4 int a[MAXN][MAXN]; 5 int main() 6 { 7 int n, q, l, r; 8 while (cin >> n) 9 { 10 memset(a, 0, sizeof a); 11 for (int i = 1; i <= n; i++) cin >> a[i][i]; 12 for (int i = 2; i <= n; i++) 13 { 14 for (int j = 1; j <= n - i + 1; j++) 15 { 16 a[j][j + i - 1] = a[j][j + i - 2] ^ a[j + 1][j + i - 1]; 17 } 18 } 19 for (int i = 2; i <= n; i++) 20 { 21 for (int j = 1; j <= n - i + 1; j++) 22 { 23 a[j][j + i - 1] = max(a[j][j + i - 1], max(a[j][j + i - 2], a[j + 1][j + i - 1])); 24 } 25 } 26 cin >> q; 27 while (q--) 28 { 29 cin >> l >> r; 30 cout << a[l][r] << endl; 31 } 32 } 33 return 0; 34 }
标签:clu 区间dp name bsp ons c++ ace 思路 out
原文地址:https://www.cnblogs.com/wangyiming/p/9060310.html