题目链接: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. 开始使用 Manjaro(添加源+字体渲染去模糊+软件安装+优化配置+常见错误)(30)

    1. 添加 archlinux 镜像源 1. 步骤一 向 /etc/pacman.d/mirrorlist 中添加国内镜像地址 1.1 方法1:自动添加 1. 输入如下命令查看国内镜像源,并按质量排序 ...

  2. 第二章 Python基础语法

    2.1 环境的安装 解释器:py2 / py3 (环境变量) 开发工具:pycharm 2.2 编码 编码基础 ascii ,英文.符号,8位为一个东西,2**8 unicode ,万国码,可以表示所 ...

  3. Oracle和SQL Server 用当前日期减去 '0001-01-01' 得出的天数不一致,相差2天,谁知道原因?

    Oracle和SQL Server 用当前日期减去 '0001-01-01' 得出的天数不一致,相差2天.求大佬科普

  4. springboot整合druid、mybatis

    目的: 1.springboot配置数据库连接池druid 测试druid中url监控 2.springboot整合mybatis 测试查删案例 3.springboot整合pagehelper sp ...

  5. Spring Boot集成Mybatis完整实例

    步骤: 添加Mybatis依赖: 添加数据库依赖: 配置属性文件: (具体的属性名称可以在jar包中找到) 内容: 建表sql: Mapper文件的头: 集成Mybatis的配置文件中的具体内容可以在 ...

  6. L2范数归一化概念和优势

    1 归一化处理        归一化是一种数理统计中常用的数据预处理手段,在机器学习中归一化通常将数据向量每个维度的数据映射到(0,1)或(-1,1)之间的区间或者将数据向量的某个范数映射为1,归一化 ...

  7. Android NDK 学习之接受Java传入Object数组

    本博客主要是在Ubuntu 下开发,且默认你已经安装了Eclipse,Android SDK, Android NDK, CDT插件. 在Eclipse中添加配置NDK,路径如下Eclipse-> ...

  8. Android NDK 学习之Android.mk

    Android.mk file syntax specification Introduction: This document describes the syntax of Android.mk  ...

  9. 流程控制 while for

    循环执行 计算机最擅长的功能之一就是按照规定的条件,重复执行某些操作,这是程序设计中最能发挥计算机特长的程序结构. 1.while语句 while(表达式){ 各种语句.... } 当表达式的值为tr ...

  10. SQLSEVER 不同服务器下两个结构相似的表实现数据同步(触发器)

    1.建立链接服务器 在ServerA 中创建指向ServerB的链接服务器,并做好账号映射.addlinkedserver存储过程创建一个链接服务器,参数详情参见官方文档. 第1个参数LNK_Serv ...