CF1523D Love-Hate
抽象化题意:
一共有 \(m\) 个元素,给定 \(n\) 个集合,每个集合的元素不超过 \(15\) 个,求出一个元素个数最多的集合 \(S\) 是至少 \(\lceil \dfrac{n}{2} \rceil\) 个集合的子集。
其中$ p $ $ (1 \le n \le 2 \cdot 10^5, 1 \le p \le m \le 60) $
我们先假设 \(limit= \lceil \dfrac{n}{2} \rceil\)
先考虑最基础的暴力,如果我们每次枚举答案集合 \(S\) ,然后再计算出是否有大于等于 \(limit\) 个集合是 \(S\) 的超集,更新答案
计算超集可以通过 \(SOSDP\) ,仍然TLE,先从题目本质入手,它是让我们求一个集合使得是至少 \(\lceil \dfrac{n}{2} \rceil\) 个集合的子集,那么这个答案显然是某 \(\lceil \dfrac{n}{2} \rceil\) 个集合的子集,那如果我们随机任取一个集合,正确答案是它子集的概率就是50%,那我们直接随 \(num\) 次,可以直接让答案错误的概率降到极低,错误的概率就是 \(\dfrac{1}{2^{num}}\) 。
也就是说随机50次的样子,每次对于随机到的集合,通过 \(O(p\times2^p)\) 来计算超集,具体细节就是需要搞个vector来存某位是1的位置就行了。
代码:
#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T>
inline T read(){
T r=0,f=0;
char c;
while(!isdigit(c=getchar()))f|=(c=='-');
while(isdigit(c))r=(r*10)+(c^48),c=getchar();
return f?-r:r;
}
int n,m,p,limit;
int a[200005];
bool flag[200005];
vector<int>g;
inline int idx(char c){
return c-'0';
}
int dp[1000005];
int ans;
mt19937 rd(time(0));
inline void work(){
int pos;
while(1){
pos=rd()%n+1;
if(!flag[pos]){flag[pos]=true;break;}
}
g.clear();
int num=a[pos];
for(int i=0;i<m;i++){
if((num>>i)&1)g.emplace_back(i);
}
memset(dp,0,sizeof(dp));
int S=g.size();
for(int i=1;i<=n;i++){
int tmp=0;
for(int j=0;j<S;j++){
if((a[i]>>g[j])&1)tmp|=(1<<j);
}
++dp[tmp];
}
for(int i=0;i<S;i++){
for(int j=0;j<(1ll<<S);j++){
if(!((j>>i)&1))dp[j]+=dp[j^(1<<i)];
}
}
int res=0;
for(int i=1;i<(1ll<<S);i++){
if(dp[i]>=limit){
if(__builtin_popcountll(res)<__builtin_popcountll(i))res=i;
}
}
int res2=0;
for(int i=0;i<S;i++){
if((res>>i)&1)res2|=(1ll<<g[i]);
}
if(__builtin_popcountll(res)>__builtin_popcountll(ans))ans=res2;
}
signed main(){
n=read<int>(),m=read<int>(),p=read<int>();
limit=(n+1)>>1;
for(int i=1;i<=n;i++){
char c;
for(int j=0;j<m;j++){
cin>>c;
if(idx(c))a[i]|=(1ll<<j);
}
}
for(int t=1;t<=min(n,50ll);t++)work();
for(int i=0;i<m;i++)
((ans>>i)&1)?putchar('1'):putchar('0');
puts("");
return 0;
}
CF1523D Love-Hate的更多相关文章
- 2021record
2021-10-14 P2577 [ZJOI2004]午餐 2021-10-13 CF815C Karen and Supermarket(小小紫题,可笑可笑) P6748 『MdOI R3』Fall ...
随机推荐
- 2019-10-31-VisualStudio-断点调试详解
title author date CreateTime categories VisualStudio 断点调试详解 lindexi 2019-10-31 8:56:7 +0800 2019-06- ...
- React项目中报错:Parsing error: The keyword 'import' is reservedeslint
记得更改完配置后,要重启编辑器(如:VSCode)!!! 记得更改完配置后,要重启编辑器(如:VSCode)!!! 记得更改完配置后,要重启编辑器(如:VSCode)!!! 这个错误通常发生在你尝试在 ...
- Codeforces 题解集
Codeforces Round 940 (Div. 2) and CodeCraft-23 Codeforces Round 940 (Div. 2) and CodeCraft-23 (A-E)
- sql计算列中并非零值的平均值
avg不考虑空值 AVG (NULLIF(Value, 0)) NULLIF(expression, expression) 如果两个 expression 相等,则返回 NULL,该 NULL 为第 ...
- cesium教程7-官方示例翻译-模型要素选择
源代码示例: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...
- Kettle下载和安装
一.Kettle简介 Kettle 是 PDI 以前的名称,PDI 的全称是Pentaho Data Integeration,Kettle 本意是水壶的意思,表达了数据流的含义.Kettle是一款国 ...
- 超详细!深入分析PPTP虚拟专用网搭建与抓包
PPTP虚拟专用网搭建与抓包分析实验 实验目的:掌握PPP协议VPN的搭建,通过分析pptp建立,理解chap连接建立的过程 实验过程: 环境搭建 Windows 11系统 VMware虚拟机.kal ...
- WPF绑定数据源到ListBox等selector的注意事项
如果使用CollectionViewSource绑定到控件上,会导致默认选择第一项,而使用List,SelectedItem就默认为空. 要避免默认选择第一项,就要设置 ListBox.IsSynch ...
- Java计算百分比保留整数
1.Java计算百分比保留整数的方法步骤 在Java中计算百分比并保留整数,通常涉及以下步骤: (1)计算原始数值与基准数值的百分比(通常使用 (原始数值 / 基准数值) * 100 的公式). (2 ...
- CSS操作——背景属性
1.background-color(背景颜色) 页面的背景颜色有四种属性值表示,分别是transparent(透明),RGB十进制颜色表示,十六进制颜色表示和颜色单词表示. 属性使用: /* bac ...