当前位置:网站首页>Codeforces Round #750 (Div. 2) F.Korney Korneevich and XOR (easy&&hard version)(dp)
Codeforces Round #750 (Div. 2) F.Korney Korneevich and XOR (easy&&hard version)(dp)
2022-07-28 17:07:00 【Code92007】
subject
The length is n Sequence , The first i The values are ai,
easy:n<=1e5,0<=ai<=500
hard:n<=1e6,0<=ai<=5000
For all strictly ascending subsequences in the sequence ,
The values of each sequence are XORed , Get a value v,
Output v The number of species , Output all in ascending order v The possibility of
Source of ideas
quality Code (hard)
Answer key
easy:
violence bitset Maintain reachable sets , Every violent XOR ,1e5*500*500/64
dp[i] Indicates that the current XOR is out i Sequence minimum of
hard:
dp[i][j] Indicates that the current sequence ends with i when , Subsequences can be XOR j when , End value of subsequence i The minimum position of
In actual implementation , Due to the need to transfer according to the prefix , The actual need does not exceed i
Experience
The feeling still uses the essence of strict ascending subsequence ,
Or the last value of the subsequence is as small as possible ,
Or when the same value is reached, the position should be as far forward as possible
Code 1(easy)
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
using namespace std;
typedef long long ll;
const int N=515,INF=0x3f3f3f3f;
int ans[N],c;
int n,now[N],v;
int main(){
memset(now,INF,sizeof now);
now[0]=0;
scanf("%d",&n);
for(int i=1;i<=n;++i){
scanf("%d",&v);
for(int j=0;j<512;++j){
if(now[j]<v){
now[j^v]=min(now[j^v],v);
}
}
}
for(int j=0;j<512;++j){
if(now[j]<INF){
ans[++c]=j;
}
}
printf("%d\n",c);
for(int i=1;i<=c;++i){
printf("%d%c",ans[i]," \n"[i==c]);
}
return 0;
}Code 2(hard)
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <bitset>
using namespace std;
const int N=5e3+1,M=8192,INF=0x3f3f3f3f;
//dp[i][j]: Subsequence tail <=i when , Can be exclusive or out j The smallest sequence position of
int n,v,dp[N][M],ans[M],c;
vector<int>pos[N];
int main(){
memset(dp,INF,sizeof dp);
scanf("%d",&n);
for(int i=1;i<=n;++i){
scanf("%d",&v);
pos[v].push_back(i);
}
dp[0][0]=0;
for(int i=1;i<N;++i){
for(int j=0;j<M;++j){
dp[i][j]=dp[i-1][j];
if(pos[i].empty())continue;
if(i==j){
dp[i][j]=min(dp[i][j],pos[i].front());
}
int id=upper_bound(pos[i].begin(),pos[i].end(),dp[i-1][j^i])-pos[i].begin();
if(id!=pos[i].end()-pos[i].begin()){
dp[i][j]=min(dp[i][j],pos[i][id]);
}
}
}
for(int j=0;j<M;++j){
if(dp[N-1][j]!=INF){
ans[++c]=j;
}
}
printf("%d\n",c);
for(int i=1;i<=c;++i){
printf("%d%c",ans[i]," \n"[i==c]);
}
return 0;
}
边栏推荐
- 13 differences between MySQL and Oracle
- 【深度学习】:《PyTorch入门到项目实战》第二天:从零实现线性回归(含详细代码)
- HTAP是有代价的
- 如何使用Fail2Ban保护WordPress登录页面
- 阿里大哥教你如何正确认识关于标准IO缓冲区的问题
- 打造自组/安全/可控的LoRa网!Semtech首度回应“工信部新规”影响
- Games101 assignment04 job 04
- 做题笔记2(两数相加)
- Reduce cycle complexity
- Games101-assignment05 ray tracing - rays intersect triangles
猜你喜欢

Realize the reset function of steering wheel UI with touch rotation and finger departure in unity

Applet: scroll view slides to the bottom by default

mysql 最大建议行数2000w,靠谱吗?

【深度学习】:《PyTorch入门到项目实战》第二天:从零实现线性回归(含详细代码)

Re12:读论文 Se3 Semantic Self-segmentation for Abstractive Summarization of Long Legal Documents in Low

结构化设计的概要与原理--模块化

Do you really understand CMS garbage collector?

Unity shader transparent effect

Binary representation of negative integers and floating point numbers

ERROR: transport library not found: dt_ socket
随机推荐
Exercise note 5 (square of ordered array)
记录开发问题
Programmers from entry to roast!!!!
做题笔记4(第一个错误的版本,搜索插入位置)
Re10:读论文 Are we really making much progress? Revisiting, benchmarking, and refining heterogeneous gr
【深度学习】:《PyTorch入门到项目实战》第六天:多层感知机(含代码)
Semtech推出物联网地理定位解决方案LoRa Edge,首款芯片LR1110现已上市
飞马D200S无人机与机载激光雷达在大比例尺DEM建设中的应用
【深度学习】:《PyTorch入门到项目实战》第四天:从0到1实现logistic回归(附源码)
Applet: scroll view slides to the bottom by default
记录ceph两个rbd删除不了的处理过程
[deep learning]: day 5 of pytorch introduction to project practice: realize softmax regression from 0 to 1 (including source code)
阿里云-武林头条-建站小能手争霸赛
华为Mate 40系列曝光:大曲率双曲面屏,5nm麒麟1020处理器!还将有天玑1000+的版本
SUSE CEPH rapid deployment – storage6
SUSE CEPH add nodes, reduce nodes, delete OSD disks and other operations – storage6
Brother Ali teaches you how to correctly understand the problem of standard IO buffer
The longest substring of sword finger offer without repeated characters
Rsync 服务部署与参数详解
Ruoyi集成flyway后启动报错的解决方法