题目链接: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. poj1056(字符串判断是否存在一个字符串是另一个字符串的前缀)

    题目链接:https://vjudge.net/problem/POJ-1056 题意:给定一个字符串集,判断是否存在一个字符串是另一个字符串的前缀. 思路:和hdoj1671一样,有两种情况: 当前 ...

  2. vue之$event获取当前元素的节点

    <p @click = “clickfun($event)”>点击</p> methods: { clickfun(e) { // e.target 是你当前点击的元素 // ...

  3. `GLIBCXX_3.4.15' not found when using mex file in matlab (linux)

    from: http://www.360doc.com/content/14/0314/16/175261_360565922.shtml Invalid MEX-file '*/*/*.mexa64 ...

  4. 死锁造成oom的排错

    1.死锁的查看步骤 jps -l jstack xxxx(xxxx为java进程的进程号) ------ 2:查看java进程的参数: jps -l jinfo -flag printGcDetial ...

  5. Zero-shot Learning / One-shot Learning / Few-shot Learning

    Zero-shot Learning / One-shot Learning / Few-shot Learning Learning类型:Zero-shot Learning.One-shot Le ...

  6. GraphHopper-初识

    GraphHopper  GraphHopper is a fast and Open Source road routing engine.   Is fast and memory efficie ...

  7. CodeForces-1159B-Expansion coefficient of the array

    B. Expansion coefficient of the array time limit per test:1 second memory limit per test:256 megabyt ...

  8. 利用Anaconda软件安装opencv模块

    先说明我安装opencv环境的原因:因为我Anaconda中创建了tensorflow和pytorch虚拟环境,想在每个虚拟环境下都安装opencv模块,这样在后期进行代码调试的时候更加便捷,以下是我 ...

  9. 计算机网络自顶向下方法第3章-传输层 (Transport Layer).2

    3.5 面向连接的运输: TCP 3.5.1 TCP连接 TCP是因特网运输层的面向连接的可靠的运输协议. TCP连接提供全双工服务(full-duplex service). TCP连接是点对点的连 ...

  10. go String方法的实际应用

    让 IPAddr 类型实现 fmt.Stringer 以便用点分格式输出地址. 例如,`IPAddr{1,`2,`3,`4}` 应当输出 `"1.2.3.4"`. String() ...