Codeforces Round #533 (Div. 2) E. Helping Hiasat(最大独立集)
题目链接: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(最大独立集)的更多相关文章
- Codeforces Round #533 (Div. 2) E - Helping Hiasat 最大团
E - Helping Hiasat 裸的最大团,写了一种 2 ^ (m / 2) * (m / 2)的复杂度的壮压, 应该还有更好的方法. #include<bits/stdc++.h> ...
- Codeforces Round #533 (Div. 2)题解
link orz olinr AK Codeforces Round #533 (Div. 2) 中文水平和英文水平都太渣..翻译不准确见谅 T1.给定n<=1000个整数,你需要钦定一个值t, ...
- Codeforces Round #533 (Div. 2)
C: 题意: 有n个整数ai,数列a有两个神奇的性质.1.所有的整数都在[l,r]范围内.2.这n个数的和能被3整除.现在给出l和r,和个数n,问你有多少种方法构造出数列a,方案数mod1e9+7. ...
- Codeforces Round #533 (Div. 2) Solution
A. Salem and Sticks 签. #include <bits/stdc++.h> using namespace std; #define N 1010 int n, a[N ...
- Codeforces Round #533 (Div. 2) E 最大独立集
知识点 最大独立集(set) = 补图的最大团(clique ) 最小顶点覆盖 + 最大独立集 = V E. Helping Hiasat time limit per test 2 seconds ...
- Codeforces Round #533 (Div. 2) C.思维dp D. 多源BFS
题目链接:https://codeforces.com/contest/1105 C. Ayoub and Lost Array 题目大意:一个长度为n的数组,数组的元素都在[L,R]之间,并且数组全 ...
- 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 ...
- 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 ...
- Codeforces Round #533(Div. 2) C.Ayoub and Lost Array
链接:https://codeforces.com/contest/1105/problem/C 题意: 给n,l,r. 一个n长的数组每个位置可以填区间l-r的值. 有多少种填法,使得数组每个位置相 ...
随机推荐
- [转帖]大数据hadoop与spark的区别
大数据hadoop与spark的区别 https://www.cnblogs.com/adnb34g/p/9233906.html Posted on 2018-06-27 14:43 左手中倒影 阅 ...
- lnmp 是不是该吐吐槽
lnmp 提供提供了便捷 , 并且手也伸的挺长的,它已不仅仅是个服务器环境那么简单 作为服务器继承环境来讲,可能每个人的认知程度不一,总之用了它需要服从它的规则 但从个人感觉上,其埋的坑还是让人不适, ...
- python基础学习(十一)
22.类 # 类 class # 实例 实体 instance class Student: # 空语句 保持结构的完整性 pass jack = Student() jack.name = &quo ...
- Cookie,Session,Token详解
Cookie,Session,Token详解 Cookie : 是一个非常具体的东西,指的就是浏览器里面能永久存储的一种数据,仅仅是浏览器实现的一种数据存储功能. Cookie由服务器生成,发 ...
- shell从简单到脱坑
1.计算1-100的和(seq 1 100 使用反引号括起来的比较坑) #!/bin/bash ` do sum=$[$i+$sum] done echo $sum 2.编写shell脚本,要求输入一 ...
- 20191106-基于Python的对字母基数排序
基数排序 概念 基数排序的算法过程是先将待排元素补位,使其长度一致,然后按照序列中的元素的每个位数进行分桶的一种算法. 比如待排序列是数字,则将所有待比较数值(正整数)统一为同样的数位长度,数位较短的 ...
- [tomcat] 连接池参数maxActive、maxIdle 、maxWait 等
maxActive 连接池支持的最大连接数,这里取值为20,表示同时最多有20个数据库连接.设 0 为没有限制.maxIdle 连接池中最多可空闲maxIdle个连接 ,这里取值为20,表示即使没有数 ...
- 『Python基础』第8节:格式化输出
现在有一个需求, 询问用户的姓名, 年龄, 工作, 爱好, 然后打印成以下格式 ************ info of Conan ************ name: Conan age: 23 ...
- PB学习笔记之随笔
1.根据条件改变字体颜色.if(curdate>=bdate and curdate<edate,rgb(255,0,0),if(sex=1, if(curdate>=mdate, ...
- PowerBuilder学习笔记之调用事件和函数
2.7.1调用事件和函数 完整语法:[ObjectName]ancestorclass::[type][when]name([argumnetlist]) 说明:ObjectName:指定函数或事件的 ...