E - Helping Hiasat

裸的最大团,写了一种 2 ^ (m / 2)  * (m / 2)的复杂度的壮压, 应该还有更好的方法。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long
using namespace std; const int N = 2e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = ;
const double eps = 1e-; int n, m, op;
LL e[];
int a[<<], b[<<];
string name;
set<int> Set;
map<string, int> Map; int main() {
cin >> n >> m;
for(int i = ; i <= n; i++) {
cin >> op;
if(op == ) {
Set.clear();
} else {
cin >> name;
if(Map.find(name) == Map.end())
Map[name] = SZ(Map);
int x = Map[name];
for(auto& y : Set) {
e[x - ] |= 1ll << (y - );
e[y - ] |= 1ll << (x - );
}
Set.insert(x);
}
}
int c1 = m / , c2 = m - c1;
for(int S = ; S < ( << c1); S++) {
int p = __builtin_ctz(S), tmp = ;
a[S] = max(a[S], a[S ^ ( << p)]);
for(int i = ; i < c1; i++)
if(!(e[p]>>i&)) tmp |= << i;
a[S] = max(a[S], a[tmp & (S ^ ( << p))] + );
}
for(int S = ; S < ( << c2); S++) {
int p = __builtin_ctz(S), tmp = ;
b[S] = max(b[S], b[S ^ ( << p)]);
for(int i = ; i < c2; i++)
if(!(e[p + c1]>>(i+c1)&)) tmp |= << i;
b[S] = max(b[S], b[tmp & (S ^ ( << p))] + );
}
int ans = ;
for(int S = ; S < ( << c2); S++) {
LL tmp = ;
for(int i = ; i < c2; i++)
if(S >> i & ) tmp |= e[i + c1];
for(int i = ; i < c1; i++) tmp ^= << i;
tmp &= ( << c1) - ;
ans = max(ans, b[S] + a[tmp]);
}
printf("%d\n", ans);
return ;
} /*
*/

Codeforces Round #533 (Div. 2) E - Helping Hiasat 最大团的更多相关文章

  1. Codeforces Round #533 (Div. 2) E. Helping Hiasat(最大独立集)

    题目链接:https://codeforces.com/contest/1105/problem/E 题意:有 n 个事件,op = 1 表示我可以修改昵称,op = 2 表示一个名为 s_i 的朋友 ...

  2. Codeforces Round #533 (Div. 2)题解

    link orz olinr AK Codeforces Round #533 (Div. 2) 中文水平和英文水平都太渣..翻译不准确见谅 T1.给定n<=1000个整数,你需要钦定一个值t, ...

  3. Codeforces Round #533 (Div. 2)

    C: 题意: 有n个整数ai,数列a有两个神奇的性质.1.所有的整数都在[l,r]范围内.2.这n个数的和能被3整除.现在给出l和r,和个数n,问你有多少种方法构造出数列a,方案数mod1e9+7. ...

  4. Codeforces Round #533 (Div. 2) Solution

    A. Salem and Sticks 签. #include <bits/stdc++.h> using namespace std; #define N 1010 int n, a[N ...

  5. Codeforces Round #533 (Div. 2) E 最大独立集

    知识点 最大独立集(set) = 补图的最大团(clique ) 最小顶点覆盖 + 最大独立集 = V E. Helping Hiasat time limit per test 2 seconds ...

  6. Codeforces Round #533 (Div. 2) C.思维dp D. 多源BFS

    题目链接:https://codeforces.com/contest/1105 C. Ayoub and Lost Array 题目大意:一个长度为n的数组,数组的元素都在[L,R]之间,并且数组全 ...

  7. Codeforces Round #533 (Div. 2) C. Ayoub and Lost Array 【dp】

    传送门:http://codeforces.com/contest/1105/problem/C C. Ayoub and Lost Array time limit per test 1 secon ...

  8. Codeforces Round #533 (Div. 2) B. Zuhair and Strings 【模拟】

    传送门:http://codeforces.com/contest/1105/problem/B B. Zuhair and Strings time limit per test 1 second ...

  9. Codeforces Round #533(Div. 2) C.Ayoub and Lost Array

    链接:https://codeforces.com/contest/1105/problem/C 题意: 给n,l,r. 一个n长的数组每个位置可以填区间l-r的值. 有多少种填法,使得数组每个位置相 ...

随机推荐

  1. 【bzoj2194】快速傅立叶之二 FFT

    题意:给定序列a,b,求序列c,\(c(k)=\sum_{i=k}^{n-1}a(i)b(i-k)\) Solution: \[ c(k)=\sum_{i=k}^{n-1}a(i)b(i-k)\\ c ...

  2. 前端学习 -- Css -- 盒子模式

    框模型: CSS处理网页时,它认为每个元素都包含在一个不可见的盒子里. 为什么要想象成盒子呢?因为如果把所有的元素都想象成盒子,那么我们对网页的布局就相当于是摆放盒子.我们只需要将相应的盒子摆放到网页 ...

  3. java同步代码(synchronized)中使用BlockingQueue

    说起BlockingQueue,大家最熟悉的就是生产者-消费者模式下的应用.但是如果在调用queue的上层代码加了同步块就会导致线程死锁. 例如: static BlockingQueue<St ...

  4. svn:重命名文件之后,不允许提交

    1.错误代码 org.apache.subversion.javahl.ClientException: Illegal target for the requested operation svn: ...

  5. 界面编程之QT的事件20180727

    /*******************************************************************************************/ 一.事件 1 ...

  6. nginx代理服务器3--高可用(keepalived)

    keepalived即健康检查,不停的发送心跳包检查nginx是否活着.Nginx至少两台,一主一备.

  7. Python 基础数据类型之set

    set是一个无序且不重复的元素集合,相当于字典的键,不重复,不可变 一.set变量初始化 A = set() #注意在创建空集合的时候只能使用s=set(),因为s={}创建的是空字典 B = {&q ...

  8. xen list_domains stat 解析

    XenServer中可以使用list_domains命令来查看所有VM以及Dom0的运行状态以及简单的资源消耗,如下: [root@xenserver ~]# list_domains id | uu ...

  9. Ubuntu下安装BeautifulSoup4

    先去下载beautifulsoup的安装包https://www.crummy.com/software/BeautifulSoup/bs4/download/4.0/ 下载完之后解压 tar -xv ...

  10. 分布式锁--Redis小试牛刀

    参考文章: Redis分布式锁的正确实现方式 分布式锁看这篇就够了 在这两篇文章的指引下亲测 Redis分布式锁 引言 分布式系统一定会存在CAP权衡问题,所以才会出现分布式锁 什么是CAP理论? 为 ...