当前位置:网站首页>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;
}
边栏推荐
- Re11:读论文 EPM Legal Judgment Prediction via Event Extraction with Constraints
- 综合设计一个OPPE主页--页面的售后服务
- Epoll horizontal departure, which edge triggers
- Deep understanding of deepsea and salt deployment tools – storage6
- 2019年全球移动通信基站市场:爱立信、华为、诺基亚分列前三
- 关于 CMS 垃圾回收器,你真的懂了吗?
- Implementation of paging
- leetcode647. 回文子串
- Re13:读论文 Gender and Racial Stereotype Detection in Legal Opinion Word Embeddings
- Programmers from entry to roast!!!!
猜你喜欢

Re10:读论文 Are we really making much progress? Revisiting, benchmarking, and refining heterogeneous gr
![[deep learning]: day 8 of pytorch introduction to project practice: weight decline (including source code)](/img/19/18d6e94a1e0fa4a75b66cf8cd99595.png)
[deep learning]: day 8 of pytorch introduction to project practice: weight decline (including source code)

MySQL installation tutorial

Unity editor learning (I) using features to change the display of fields in components

【深度学习】:《PyTorch入门到项目实战》第一天:数据操作和自动求导
![[deep learning]: introduction to pytorch to project practice: simple code to realize linear neural network (with code)](/img/19/18d6e94a1e0fa4a75b66cf8cd99595.png)
[deep learning]: introduction to pytorch to project practice: simple code to realize linear neural network (with code)

飞马D200S无人机与机载激光雷达在大比例尺DEM建设中的应用
![[deep learning]: day 4 of pytorch introduction to project practice: realize logistic regression from 0 to 1 (with source code)](/img/19/18d6e94a1e0fa4a75b66cf8cd99595.png)
[deep learning]: day 4 of pytorch introduction to project practice: realize logistic regression from 0 to 1 (with source code)

Re12: read these3 semantic self segmentation for abstract summary of long legal documents in low
![[deep learning]: model evaluation and selection on the seventh day of pytorch introduction to project practice (Part 1): under fitting and over fitting (including source code)](/img/19/18d6e94a1e0fa4a75b66cf8cd99595.png)
[deep learning]: model evaluation and selection on the seventh day of pytorch introduction to project practice (Part 1): under fitting and over fitting (including source code)
随机推荐
Mysql与Oracle的13点区别
Ugui learning notes (V) togglegroup makes multiple choice radio boxes
阿里云 MSE 支持 Go 语言流量防护
13 differences between MySQL and Oracle
Unity editor learning (I) using features to change the display of fields in components
Detailed steps for setting up SUSE storage6 environment – win10 + VMware Workstation
Technology sharing | how to recover the erroneously deleted table and the data in the table?
epoll水平出发何边沿触发
Add differential pairs and connections in Ad
TCP handshake, waving, time wait connection reset and other records
[deep learning]: day 5 of pytorch introduction to project practice: realize softmax regression from 0 to 1 (including source code)
HTAP是有代价的
记录开发问题
2020Q2全球平板市场出货大涨26.1%:华为排名第三,联想增幅最大!
asmlinkage的理解
如何使用Fail2Ban保护WordPress登录页面
Applet: scroll view slides to the bottom by default
Jsonarray traversal
技术分享 | 误删表以及表中数据,该如何恢复?
Hikvision responded to the impact of the 'US ban': there are options for the components currently used