当前位置:网站首页>Cf750f1 thinking DP
Cf750f1 thinking DP
2022-07-25 15:34:00 【Brother Tazi is here】
The main idea of the topic :
Give you a sequence , Output the set of XOR and sum of all increasing subsequences .
for example :
4
4 2 2 4
Output :
4
0 2 4 6
Because there are increasing subsequences :
0
2
4
2 4
Their XOR and set is 0 2 4 6
n ≤ 1 e 5 , a i ≤ 500 n \leq 1e5,a_i\leq500 n≤1e5,ai≤500
Topic ideas :
Simple thinking : d p ( i , j ) dp(i,j) dp(i,j) On behalf of i i i Number , Whether there is an XOR sum of increasing subsequences j.
But we need it to increase , So greedy let d p ( i , j ) dp(i,j) dp(i,j) For XOR and for j j j The smallest possible of the increasing subsequence of End value .
Then you can move .
#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;
}
边栏推荐
- ML - 语音 - 语音处理介绍
- MySQL优化总结二
- Application of C language array in Sanzi chess -- prototype of Queen n problem
- JVM-动态字节码技术详解
- Pytorch学习笔记--常用函数总结3
- ML - 自然语言处理 - 自然语言处理简介
- 谷歌云盘如何关联Google Colab
- Games101 review: 3D transformation
- matlab---错误使用 var 数据类型无效。第一个输入参数必须为单精度值或双精度值
- How to solve the login problem after the 30 day experience period of visual stuido2019
猜你喜欢

Games101 review: 3D transformation

MATLAB 如何生产随机复序列

Brain racking CPU context switching

4PAM在高斯信道与瑞利信道下的基带仿真系统实验

Pat grade a 1152 Google recruitment (20 points)

小波变换--dwt2 与wavedec2

谷歌云盘如何关联Google Colab

MySQL transactions and mvcc

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

Ml speech depth neural network model
随机推荐
2021 Shanghai match-h-two point answer
2021 Shanghai sai-d-cartland number variant, DP
Pytorch学习笔记--Pytorch常用函数总结1
Endnote 添加中文GBT7714样式 word中如何引用文献
How to solve the login problem after the 30 day experience period of visual stuido2019
2021 Shanghai match-b-ranked DP
Take you to learn more about JS basic grammar (recommended Collection)
GAMES101复习:线性代数
CGO is realy Cool!
How to update JSON values in the database?
SQL cultivation manual from scratch - practical part
GAMES101复习:三维变换
2019陕西省省赛J-位运算+贪心
matlab randint,Matlab的randint函数用法「建议收藏」
Pytorch学习笔记-刘二老师RNN高级篇-代码注释及结果
数据系统分区设计 - 分区再平衡(rebalancing)
MySQL optimization summary II
Matlab randInt, matlab randInt function usage "recommended collection"
2021上海市赛-B-排序后dp
Xcode added mobileprovision certificate file error: Xcode encoded an error