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. 思路:先处理出前缀异或,这样 ...
随机推荐
- Centos下搭建golang环境
一.下载安装包 先查看一下我的Centos版本,这里是6.4. # cat /etc/redhat-release CentOS release 6.4 (Final) 去go语言中文社区下载想要下载 ...
- host元素的属性autoDeploy和reloadable的区别
web.xml文件的修改会触发AutoDeploy,受host节的autoDeploy配置值的影响. class类文件修改会触发Reload操作,受reloadable配置值的影响. 而autoDep ...
- maven单元测试报java.lang.IllegalStateException: Failed to load ApplicationContext
报这个异常java.lang.IllegalStateException: Failed to load ApplicationContext的时候,通常是因为applicationContent.x ...
- Iris Classification on PyTorch
Iris Classification on PyTorch code # -*- coding:utf8 -*- from sklearn.datasets import load_iris fro ...
- linux 关于redis-trib.rb构建redis集群
之前搭建集群漏下的坑, 今次再搭一次. 环境 ruby环境 yum install ruby rubygems -y redis的gem环境 gem install redis-3.2.2.gem 部 ...
- Linux基础笔记—— 走进Linux
走进Linux 操作系统 操作系统是计算机中必不可少的基础系统软件,他的作用是管理和控制计算机系统中的硬件和软件资源,合理有效的组织系统的工作流程,在计算机系统(硬件)与使用者之间提供接口作用. 操作 ...
- 树之105 Construct Binary Tree from Preorder and Inorder Traversal
题目链接:https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/ 参考链 ...
- Restful framework【第八篇】频率组件
基本使用 频率: -限制每个ip地址一分钟访问10次 -写一个类 from rest_framework.throttling import SimpleRateThrottle class Visi ...
- Ajax详细剖析
概述 对于WEB应用程序:用户浏览器发送请求,服务器接收并处理请求,然后返回结果,往往返回就是字符串(HTML),浏览器将字符串(HTML)渲染并显示浏览器上. 传统的Web应用 一个简单操作需要重新 ...
- LuoguP3948 数据结构
题目地址 题目链接 题解 以为这题虽然是数据随机也不至于那么水吧... 于是秉着先打部分分和暴力的原则先写了暴力和min,max为-inf和inf的特殊点,对于暴力搞了个小优化,延后的操作直接前缀和答 ...