当前位置:网站首页>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 - natural language processing - Key Technologies
- Understanding the difference between wait() and sleep()
- Binary complement
- JVM parameter configuration details
- p4552-差分
- JVM知识脑图分享
- Delayed loading source code analysis:
- Xcode添加mobileprovision证书文件报错:Xcode encountered an error
- Pytorch学习笔记--常用函数总结3
- Application of C language array in Sanzi chess -- prototype of Queen n problem
猜你喜欢

解决vender-base.66c6fc1c0b393478adf7.js:6 TypeError: Cannot read property ‘validate‘ of undefined问题

ML - natural language processing - Key Technologies

Pytorch学习笔记--Pytorch常用函数总结1

理解“平均负载”

Are you ready to break away from the "involution circle"?

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

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

Phased summary of the research and development of the "library management system -" borrowing and returning "module

No tracked branch configured for branch xxx or the branch doesn‘t exist. To make your branch trac

Take you to create your first C program (recommended Collection)
随机推荐
Hdu3873 shortest path with dependency (topological sorting)
2021上海市赛-D-卡特兰数变种,dp
Xcode added mobileprovision certificate file error: Xcode encoded an error
看到很多App出现闪烁的图片,特别是会员页面
matlab--CVX优化工具包安装
Games101 review: linear algebra
CF685B-求有根树每颗子树的重心
Are you ready to break away from the "involution circle"?
Args parameter parsing
window系统黑窗口redis报错20Creating Server TCP listening socket *:6379: listen: Unknown error19-07-28
Games101 review: 3D transformation
数据系统分区设计 - 请求路由
How to solve the login problem after the 30 day experience period of visual stuido2019
数据系统分区设计 - 分区再平衡(rebalancing)
JVM-垃圾收集器详解
盒子躲避鼠标
CGO is realy Cool!
Binary complement
Get the ask code corresponding to the key pressed by the keyboard
Idea eye care settings