当前位置:网站首页>CF750F1-思维dp
CF750F1-思维dp
2022-07-25 15:23:00 【塔子哥来了】
题目大意:
给你一个序列,输出里面的所有递增子序列的异或和的集合.
例如:
4
4 2 2 4
输出:
4
0 2 4 6
因为有递增子序列:
0
2
4
2 4
他们的异或和的集合就是 0 2 4 6
n ≤ 1 e 5 , a i ≤ 500 n \leq 1e5,a_i\leq500 n≤1e5,ai≤500
题目思路:
朴素的思考: d p ( i , j ) dp(i,j) dp(i,j)代表前 i i i个数,是否存在递增子序列的异或和为j.
但是我们需要其递增,所以贪心的让 d p ( i , j ) dp(i,j) dp(i,j)为异或和为 j j j的递增子序列的最小的可能的结尾值。
然后就可以转移了。
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int inf = 0x3f3f3f3f;
int a[maxn];
int dp[513] , g[513];
int main()
{
int n;
cin >> n;
for (int i = 1 ; i <= n ; i++) cin >> a[i];
memset(dp , 0x3f , sizeof dp);
dp[0] = 0;
for (int i = 1 ; i <= n ; i++){
memcpy(g , dp , sizeof g);
for (int j = 0 ; j < 512 ; j++){
if (g[j] < a[i]){
int k = j ^ a[i];
dp[k] = min(g[k] , a[i]);
}
}
}
vector<int> ans;
for (int i = 0 ; i < 512 ; i++) if (dp[i] != inf) ans.push_back(i);
cout << ans.size() << endl;
for (auto g : ans) cout << g << " ";
cout << endl;
return 0;
}
边栏推荐
- Spark SQL common time functions
- 在网页上实现任意格式的音视频快速播放功能的开发总结。
- C#精挑整理知识要点9 集合2(建议收藏)
- <栈模拟递归>
- 苹果内购和Apple Pay 的区别
- spark中saveAsTextFile如何最终生成一个文件
- Run redis on docker to start in the form of configuration file, and the connection client reports an error: server closed the connection
- matlab 如何保存所有运行后的数据
- Delayed loading source code analysis:
- 小波变换--dwt2 与wavedec2
猜你喜欢

MySQL transactions and mvcc

matlab---错误使用 var 数据类型无效。第一个输入参数必须为单精度值或双精度值

Application of C language array in Sanzi chess -- prototype of Queen n problem

SVD奇异值分解推导及应用与信号恢复

CF888G-巧妙字典树+暴力分治(异或最小生成树)

Single or multiple human posture estimation using openpose

Overview of JS synchronous, asynchronous, macro task and micro task

How to solve the login problem after the 30 day experience period of visual stuido2019

Application of object detection based on OpenCV and yolov3

Yan required executor memory is above the max threshold (8192mb) of this cluster!
随机推荐
Flex 布局
Understanding the execution order of T-SQL query from the execution order of join on and where
Is it safe to open futures online? Which company has the lowest handling charge?
Spark获取DataFrame中列的方式--col,$,column,apply
Word 样式模板复制到另一文档
UIDocumentInteractionController UIDocumentPickerViewController
Single or multiple human posture estimation using openpose
In depth: micro and macro tasks
Submarine cable detector tss350 (I)
redis淘汰策列
Object.prototype. Hasownproperty() and in
HDU3873-有依赖的最短路(拓扑排序)
Implementation of asynchronous FIFO
window系统黑窗口redis报错20Creating Server TCP listening socket *:6379: listen: Unknown error19-07-28
期货在线开户是否安全?去哪家公司手续费最低?
IOS interview questions
Spark memory management mechanism new version
本地缓存--Ehcache
ML - natural language processing - Basics
JVM-动态字节码技术详解