题目链接:https://codeforces.com/contest/1105/problem/E

题意:有 n 个事件,op = 1 表示我可以修改昵称,op = 2 表示一个名为 s_i 的朋友查询我当前的名字。一个朋友是高兴的当且仅当他每次查询我的名字都为 s_i,保证每个朋友至少查询一次我的名字,问最多可以有多少个朋友高兴。

题解:在我两次修改昵称之间,若出现不同的朋友,则他们是互斥的,可以在他们之间连一条边,然后求图的最大独立集,而原图的最大独立集等于补图的最大团,所以求补图的最大团即可。(模板)

 #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mst(a,b) memset((a),(b),sizeof(a))
#define mp(a,b) make_pair(a,b)
#define pi acos(-1)
#define pii pair<int,int>
#define pb push_back
#define lowbit(x) ((x)&(-x))
const int INF = 0x3f3f3f3f;
const double eps = 1e-;
const int maxn = 1e5 + ;
const int maxm = 1e6 + ;
const ll mod = 1e9 + ; int n, m, tot = ;
map<string, int>ma, have;
int op[maxn];
string s[maxn]; int mx[], g[][], f[][], ans; int dfs(int cur, int tot) {
if(!cur) {
if(tot > ans)
return ans = tot, ;
return ;
}
for(int i = , j, u, nxt; i < cur; i++) {
if(cur - i + tot <= ans)
return ;
u = f[tot][i], nxt = ;
if(mx[u] + tot <= ans)
return ;
for(j = i + ; j < cur; j++)
if(g[u][f[tot][j]])
f[tot + ][nxt++] = f[tot][j];
if(dfs(nxt, tot + ))
return ;
}
return ;
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
scanf("%d%d", &m, &n);
for(int i = ; i <= m; i++) {
scanf("%d", &op[i]);
if(op[i] == ) {
cin >> s[i];
if(ma.find(s[i]) == ma.end())
ma[s[i]] = tot++;
}
}
vector<int>vec;
for(int i = ; i <= m; i++) {
if(op[i] == ) {
have.clear();
for(int i = ; i < vec.size(); i++) {
for(int j = i + ; j < vec.size(); j++) {
g[vec[i]][vec[j]] = g[vec[j]][vec[i]] = ;
}
}
vec.clear();
} else if(have.find(s[i]) == have.end())
vec.pb(ma[s[i]]);
}
for(int i = ; i < vec.size(); i++) {
for(int j = i + ; j < vec.size(); j++) {
g[vec[i]][vec[j]] = g[vec[j]][vec[i]] = ;
}
}
for(int i = ; i < n; i++)
for(int j = ; j < n; j++)
g[i][j] ^= ; int j,k;
for(int i = n - ; ~i; dfs(k, ), mx[i--] = ans)
for(k = , j = i + ; j < n; j++)
if(g[i][j])
f[][k++] = j;
printf("%d\n", ans);
return ;
}

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

  1. Codeforces Round #533 (Div. 2) E - Helping Hiasat 最大团

    E - Helping Hiasat 裸的最大团,写了一种 2 ^ (m / 2)  * (m / 2)的复杂度的壮压, 应该还有更好的方法. #include<bits/stdc++.h> ...

  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. 转:Cesium 和 Webpack

    原文地址:https://www.jianshu.com/p/85917bcc023f 注意:webpack 和 webpack-cli 的安装参考 https://www.cnblogs.com/m ...

  2. docker 实践四:数据管理

    这篇是关于 docker 的数据管理. 注:环境为 CentOS7,docker 19.03. 一般容器中管理数据主要有两种方式: 数据卷(Data Volumes):容器内数据直接映射到本地主机环境 ...

  3. 使用docker-compose搭建WordPress

    今天博主使用typecho各种不爽,索性干掉typecho,使用WordPress 依赖 mysql nginx yml 文件 version: '3' services: nginx: image: ...

  4. 2.33模型--去除字符串两头空格.c

    [注:本程序验证是使用vs2013版] #include <stdio.h> #include <stdlib.h> #include <string.h> #pr ...

  5. bash 和 powershell 常用命令集锦

    Linux Shell # 1. 后台运行命令 nohup python xxx.py & # 查找替换 ## 只在目录中所有的 .py 和 .dart 文件中递归搜索字符"main ...

  6. [二叉树算法]关于判断是否为BST的算法

    //判断是否为BST 搜索树==二叉排序树 1.递归知最大最小值.2.先中序判是否单调 bool IsValidBST(BTNode *p,int low,int high){ if(p==NULL) ...

  7. .ajaxStart() / .ajaxStop() —— ajax请求开始时 / 结束时触发

    一..ajaxStart()——ajax请求开始时触发  描述:ajax请求开始时触发 .ajaxStart()的回调函数,全局的,所有的ajax都可以用 写法:元素.ajaxStart(functi ...

  8. 淘宝图片指纹匹配功能c#实现

    #region 生成图片及图片比较 public String GetHash(Image SourceImg) { Image image = ReduceSize(SourceImg); Byte ...

  9. 基于【 SpringBoot】一 || QQ授权流程

    一.准备工作 1.qq开放平台应用申请,获取APP ID和APP Key 2.qq开放平台配置回调地址 二.服务器端生成授权链接 1.请求地址 https://graph.qq.com/oauth2. ...

  10. weui中的picker滑动报错

    html { touch-action: none; } 在页面插入上述代码即可解决