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的更多相关文章

  1. Codeforces 627 A. XOR Equation (数学)

    题目链接:http://codeforces.com/problemset/problem/627/A 题意: 告诉你s 和 x,a + b = s    a xor b = x   a, b > ...

  2. Codeforces 242E:XOR on Segment(位上的线段树)

    http://codeforces.com/problemset/problem/242/E 题意:给出初始n个数,还有m个操作,操作一种是区间求和,一种是区间xor x. 思路:昨天比赛出的一道类似 ...

  3. Codeforces 617 E. XOR and Favorite Number

    题目链接:http://codeforces.com/problemset/problem/617/E 一看这种区间查询的题目,考虑一下莫队. 如何${O(1)}$的修改和查询呢? 令${f(i,j) ...

  4. Codeforces 617E:XOR and Favorite Number(莫队算法)

    http://codeforces.com/problemset/problem/617/E 题意:给出n个数,q个询问区间,问这个区间里面有多少个区间[i,j]可以使得ai^ai+1^...^aj ...

  5. codeforces 617 E. XOR and Favorite Number(莫队算法)

    题目链接:http://codeforces.com/problemset/problem/617/E 题目: 给你a1 a2 a3 ··· an 个数,m次询问:在[L, R] 里面又多少中 [l, ...

  6. CodeForces 280B Maximum Xor Se

    题目链接:http://codeforces.com/contest/280/problem/B 题目大意: 给定一个由n个数组成的一个序列,s[l..r] (1 ≤ l < r ≤ n)代表原 ...

  7. Codeforces 242 E. XOR on Segment

    题目链接:http://codeforces.com/problemset/problem/242/E 线段树要求支持区间求和,区间内每一个数字异或上一个值. 既然是异或,考虑每一个节点维护一个长度为 ...

  8. 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 ...

  9. codeforces 354 D. Transferring Pyramid

    D. Transferring Pyramid time limit per test 3 seconds memory limit per test 256 megabytes input stan ...

  10. codeforces 1101G (Zero XOR Subset)-less 前缀异或+线性基

    题目传送门 题意:给出一个序列,试将其划分为尽可能多的非空子段,满足每一个元素出现且仅出现在其中一个子段中,且在这些子段中任取若干子段,它们包含的所有数的异或和不能为0. 思路:先处理出前缀异或,这样 ...

随机推荐

  1. fjwc2019 D2T3 排序(堆)

    #183. 「2019冬令营提高组」排序 贴一段ppt 考虑模拟出这个算法进行k轮(即外层的i循环到k)时的序列,之后再暴力模拟零散的步. 考虑这个算法在01序列上的表现,k轮后实际上就是将最开始的不 ...

  2. ORA-30377 MV_CAPABILITIES_TABLE not found

    Cause: You have used the DBMS_MVIEW.EXPLAIN_MVIEW() API before you have defined the MV_CAPABILITIES_ ...

  3. java不常用但很有用的问题排查工具(持续完善)

    因为用的频率不是很多,老忘掉,每次都要搜下,特记录下备忘. 查看进程的启动jvm选项 [root@iZ23nn1p4mjZ ~]# jinfo -flags 16603Attaching to pro ...

  4. shell &&,||,()

    做个笔记. 1. linux命令返回值介绍 shell 在执行某个命令时,会有一个返回值,该值保存在shell变量$?中.当$?为0时,表示命令执行成功:当$?为1时,表示命令执行失败. 2. &am ...

  5. nodejs 开发,手把手开始第一个服务器程序(原生)

    此文章为原生 nodejs  ,仅做学习使用 想学习 express 和 koa2 的小伙伴请绕路 此文章适合有HTML 和css .js 基础的小伙伴看哦 如果能帮到你,荣幸之至 文章纯手打,如有纰 ...

  6. Iterator和Iterable的区别以及使用

    Iterator和Iterable的区别以及使用   1.什么是迭代器 迭代器(iterator)是一种对象,它能够用来遍历标准模板库容器中的部分或全部元素,每个迭代器对象代表容器中的确定的地址.迭代 ...

  7. Codeforces 40E Number Table - 组合数学

    题目传送门 传送门I 传送门II 题目大意 给定一个$n\times m$的网格,每个格子上要么填$1$,要么填$-1$,有$k$个位置上的数是已经填好的,其他位置都是空的.问有多少种填法使得任意一行 ...

  8. InstallShield安装包在Win7下权限问题的解决方案 (转载)

    转载:http://blog.csdn.net/wuzhengqing1/article/details/6570149 转载:http://blog.csdn.net/brikoff/article ...

  9. 尚硅谷面试第一季-07Spring Bean的作用域之间有什么区别

    目录结构: 关键性代码: beans.xml <!-- ★bean的作用域 可以通过scope属性来指定bean的作用域 -singleton:默认值.当IOC容器一创建就会创建bean的实例, ...

  10. 【python40--类和对象:一些相关的BIF】

    0.如何判断一个类是否为另外一个类的子类 --使用issubclass(class,classinfo)函数,如果第一个函数(class)是第二个参数(classinfo)的一个子类,则返回Ture, ...