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. P2044 [NOI2012]随机数生成器

    洛咕原题 正常的矩乘题. 但是,计算过程中会爆long long. 所以,我们要用快速(龟速)乘来解决. 快速乘,也就是把快速幂稍作修改.乘法被分成若干个加法,以时间为代价解决精度问题. #inclu ...

  2. 关于A left join B,A是否一定是主表?

    一般情况,我们作左连接 select * from A left join B  on A.id=B.a_id;一定认为A就是主表,其实还有另外的情况,我们若将sql改写成 select * from ...

  3. (4opencv)OpenCV PR 成功的收获和感悟

     2018-09-12,第一次对OpenCV PR成功 https://github.com/opencv/opencv/pull/12206 <find innercircle of cont ...

  4. ODAC(V9.5.15) 学习笔记(十二)TOraLoader

    名称 类型 说明 Columns TDAColumns 需要载入数据的每个字段定义 LoadMode TLoadMode 载入模式,包括: lmDirect 通过内部数据缓冲区载入到数据库中 lmDM ...

  5. git如何跨分支查找某个commit所属分支?

    答: git branch -a --contains <commit id>

  6. HDU 2612 Find a way(找条路)

    HDU 2612 Find a way(找条路) 00 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)   Problem  ...

  7. jquery.validate使用详解

    一.简单应用实例: 1.用class样式进行验证,用法简单,但不能自定义错误信息,只能修改jquery-1.4.1.min.js中的内置消息,也不支持高级验证规则. <script type=& ...

  8. 5、lvs使用进阶(01)

    四层.七层负载均衡的区别  https://jaminzhang.github.io/lb/L4-L7-Load-Balancer-Difference/   netfilter/iptables简介 ...

  9. HDU 4325 Flowers(树状数组+离散化)

    http://acm.hdu.edu.cn/showproblem.php?pid=4325 题意:给出n个区间和m个询问,每个询问为一个x,问有多少个区间包含了x. 思路: 因为数据量比较多,所以需 ...

  10. HDU 3635 Dragon Balls(带权并查集)

    http://acm.hdu.edu.cn/showproblem.php?pid=3635 题意: 有n颗龙珠和n座城市,一开始第i颗龙珠就位于第i座城市,现在有2种操作,第一种操作是将x龙珠所在城 ...