当前位置:网站首页>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;
}
边栏推荐
- 阿里大哥教你如何正确认识关于标准IO缓冲区的问题
- College students participated in six Star Education PHP training and found jobs with salaries far higher than those of their peers
- SUSE Storage6 环境搭建详细步骤 – Win10 + VMware WorkStation
- Huawei mate 40 series exposure: large curvature hyperboloid screen, 5nm kylin 1020 processor! There will also be a version of Tianji 1000+
- 【深度学习】:《PyTorch入门到项目实战》:简洁代码实现线性神经网络(附代码)
- 结构化设计的概要与原理--模块化
- Easypoi multi sheet export by template
- Go language slow entry - process control statement
- 关于Bug处理的一些看法
- Given positive integers n and m, both between 1 and 10 ^ 9, n < = m, find out how many numbers have even digits between them (including N and m)
猜你喜欢
![[deep learning]: day 1 of pytorch introduction to project practice: data operation and automatic derivation](/img/4e/a41eee56fc0e8d3089f105bcb63155.png)
[deep learning]: day 1 of pytorch introduction to project practice: data operation and automatic derivation

: No such file or directory

【深度学习】:《PyTorch入门到项目实战》第四天:从0到1实现logistic回归(附源码)

College students participated in six Star Education PHP training and found jobs with salaries far higher than those of their peers

大学生参加六星教育PHP培训,找到了薪水远超同龄人的工作

Tcp/ip related

【深度学习】:《PyTorch入门到项目实战》:简洁代码实现线性神经网络(附代码)

Unity shader transparent effect

MySQL 5.7 and sqlyogv12 installation and use cracking and common commands
![[deep learning]: the second day of pytorch introduction to project practice: realize linear regression from zero (including detailed code)](/img/19/18d6e94a1e0fa4a75b66cf8cd99595.png)
[deep learning]: the second day of pytorch introduction to project practice: realize linear regression from zero (including detailed code)
随机推荐
记录ceph两个rbd删除不了的处理过程
概率论与数理统计第一章
Re12: read these3 semantic self segmentation for abstract summary of long legal documents in low
Epoll horizontal departure, which edge triggers
Probability theory and mathematical statistics Chapter 1
Unity3d simple implementation of water surface shader
Facet experience -- the development side of dragon game client
Easypoi multi sheet export by template
NoSQL introduction practice notes I
数据库故障容错之系统时钟故障
Games101 section 13 ray tracing notes
HTAP是有代价的
Applet: scroll view slides to the bottom by default
Leetcode647. Palindrome substring
Exercise note 5 (square of ordered array)
mysql 最大建议行数2000w,靠谱吗?
2020Q2全球平板市场出货大涨26.1%:华为排名第三,联想增幅最大!
Simple addition, deletion, modification and query of commodity information
【深度学习】:《PyTorch入门到项目实战》第二天:从零实现线性回归(含详细代码)
Given positive integers n and m, both between 1 and 10 ^ 9, n < = m, find out how many numbers have even digits between them (including N and m)