Codeforces 984 D - XOR-pyramid
思路:
区间dp
dp[l][r]表示ƒ([l, r])的值
显然,状态转移方程为dp[l][r] = dp[l][r-1] ^ dp[l+1][r]
初始状态dp[i][i] = a[i]
可是,这道题求的是这段区间包含的某一连续区间的最大值
那么用差不多的转移方程再求一遍区间最大值:dp[l][r] = max(dp[l][r],dp[l][r-1],dp[l+1][r])
代码:
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define mem(a, b) memset(a, b, sizeof(a)) const int N = 5e3 + ;
int dp[N][N], a[N];
int main() {
int n, q, l, r;
scanf("%d", &n);
for (int i = ; i <= n; i++) scanf("%d", &a[i]);
for (int i = n; i >= ; i--) {
dp[i][i] = a[i];
for (int j = i+; j <= n; j++) {
dp[i][j] = dp[i][j-] ^ dp[i+][j];
}
}
for (int i = n; i >= ; i--) {
for (int j = i+; j <= n; j++) {
dp[i][j] = max(dp[i][j], max(dp[i][j-], dp[i+][j]));
}
}
scanf("%d", &q);
while(q--) {
scanf("%d %d", &l, &r);
printf("%d\n", dp[l][r]);
}
return ;
}
Codeforces 984 D - XOR-pyramid的更多相关文章
- Codeforces 627 A. XOR Equation (数学)
题目链接:http://codeforces.com/problemset/problem/627/A 题意: 告诉你s 和 x,a + b = s a xor b = x a, b > ...
- Codeforces 242E:XOR on Segment(位上的线段树)
http://codeforces.com/problemset/problem/242/E 题意:给出初始n个数,还有m个操作,操作一种是区间求和,一种是区间xor x. 思路:昨天比赛出的一道类似 ...
- Codeforces 617 E. XOR and Favorite Number
题目链接:http://codeforces.com/problemset/problem/617/E 一看这种区间查询的题目,考虑一下莫队. 如何${O(1)}$的修改和查询呢? 令${f(i,j) ...
- Codeforces 617E:XOR and Favorite Number(莫队算法)
http://codeforces.com/problemset/problem/617/E 题意:给出n个数,q个询问区间,问这个区间里面有多少个区间[i,j]可以使得ai^ai+1^...^aj ...
- codeforces 617 E. XOR and Favorite Number(莫队算法)
题目链接:http://codeforces.com/problemset/problem/617/E 题目: 给你a1 a2 a3 ··· an 个数,m次询问:在[L, R] 里面又多少中 [l, ...
- CodeForces 280B Maximum Xor Se
题目链接:http://codeforces.com/contest/280/problem/B 题目大意: 给定一个由n个数组成的一个序列,s[l..r] (1 ≤ l < r ≤ n)代表原 ...
- Codeforces 242 E. XOR on Segment
题目链接:http://codeforces.com/problemset/problem/242/E 线段树要求支持区间求和,区间内每一个数字异或上一个值. 既然是异或,考虑每一个节点维护一个长度为 ...
- CodeForces - 1101G :(Zero XOR Subset)-less(线性基)
You are given an array a1,a2,…,an of integer numbers. Your task is to divide the array into the maxi ...
- codeforces 354 D. Transferring Pyramid
D. Transferring Pyramid time limit per test 3 seconds memory limit per test 256 megabytes input stan ...
- codeforces 1101G (Zero XOR Subset)-less 前缀异或+线性基
题目传送门 题意:给出一个序列,试将其划分为尽可能多的非空子段,满足每一个元素出现且仅出现在其中一个子段中,且在这些子段中任取若干子段,它们包含的所有数的异或和不能为0. 思路:先处理出前缀异或,这样 ...
随机推荐
- 苹果笔记本充不进电怎么办_macbook充不进电解决办法
使用苹果Macbook的用户可能会遇到这种情况,使用一段时间后自己的苹果笔记本充不进电了,虽然充电器指示灯依然亮着,但是电池电脑一直充不进去,断开充电器后就直接关机的情况.通常碰到这种情况,很多用户都 ...
- 一条命令,根据进程名判断有进程输出up,无进程无输出
这个研究了好一会, 由于开发需要,提供的命令. shell命令,可以按照分号分割,也可以按照换行符分割.如果想一行写入多个命令,可以通过“';”分割. a=`ps -ef | grep nginx | ...
- 学习MFC的建议
1.继续深入学习C++的内容,打好面向对象的程序综合设计与编程基础,参考书籍<C++Primer>. 2.打好Windows编程基础(参考书<Windows程序设计>(第五版) ...
- Codeforces 789D Weird journey - 欧拉路 - 图论
Little boy Igor wants to become a traveller. At first, he decided to visit all the cities of his mot ...
- 【python54--爬虫2】
1.有道翻译 ''' |-- 代码思路解析: |-- 1.拿到网址首先查看network内Headers的:Request URL:User-Agent:From Data,这几个就是代码所需要的ur ...
- 【python36--对象】
1.对象=属性+方法 2.实例化对象 #类名称首字母大写 class Turle: #属性 color = 'green' weight = 10 legs = 4 shell = True mout ...
- topcoder srm 700 div1 -3
1.有$n$个人,编号1到$n$.将其平均分到$m$个房间中,每个房间$K$个人.现在知道每个房间编号最小的人的编号.对于给出的人$x$.问其可能在的房间有多少种? 思路:先假设其在某个房间,然后判断 ...
- ng-model绑定的是ng-option中的什么?
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script sr ...
- linux内核发生Oops时怎么办?
1. 定位发生Oops的代码 1.1 通过addr2line命令定位 aarch64-openwrt-linux-gnu-addr2line -e vmlinux ffff000008087f00 1 ...
- HDU 1689 Just a Hook (线段树区间更新+求和)
Just a Hook Problem Description In the game of DotA, Pudge's meat hook is actually the most horrible ...