Codeforces Round #533 (Div. 2)E. Helping Hiasat_求最大独立子集转换求最大团

题目链接:E. Helping Hiasat

题解:把夹在同一段1里面的人互相连边,然后问题就转换为求最大独立子集的大小,最大独立子集大小等于补图的最大团。最大图不会的可以看这篇博客,我也是看这个的

#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#define pb push_back
#define ll long long
#define PI 3.14159265
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define eps 1e-7
using namespace std;
const int N=50;
const int mod=1e9+7;
int n,m;
int g[N][N];
map<string ,int >mp;
vector<int>ve;
int ret=0;
int cnt[N],vis[N],ans;
bool dfs(int u,int d)
{
    for(int i=u+1;i<m;i++)
    {
        if(d+cnt[i]<=ans)return 0;
        if(g[u][i])
        {
            int j;
            for(j=0;j<d;j++)if(!g[i][vis[j]])break;
            if(j==d)
            {
                vis[d]=i;
                if(dfs(i,d+1))return 1;
            }
        }

    }
    if(d>ans)
    {
        ans=d;return 1;
    }
    return false;
}
int maxclique()
{
    ans=0;
    for(int i=m-1;i>=0;i--)
    {
        vis[0]=i;
        dfs(i,1);
        cnt[i]=ans;
    }
    return ans;
}
int main()
{
      std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
      cin>>n>>m;
      for(int i=0;i<=n;i++)
      {
            int op;
            if(i!=n)cin>>op;
            else op=1;
            if(op==1)
            {
                for(int j=0;j<ve.size();j++)
                {
                    for(int k=j+1;k<ve.size();k++)
                    {
                       g[ve[j]][ve[k]]=1,g[ve[k]][ve[j]]=1;
                       //cout<<"SSS"<<endl;
                    }
                }
                ve.clear();
            }
            else
            {
                string s;cin>>s;
                if(mp.count(s)==0)mp[s]=ret++;
                ve.pb(mp[s]);

            }
      }
      for(int i=0;i<m;i++)
      for(int j=0;j<m;j++)g[i][j]^=1;
      cout<<maxclique()<<endl;
}

原文地址:https://www.cnblogs.com/lhclqslove/p/10298902.html

时间: 2024-11-06 03:52:21

Codeforces Round #533 (Div. 2)E. Helping Hiasat_求最大独立子集转换求最大团的相关文章

Codeforces Round #533 (Div. 2) D. Kilani and the Game(BFS)

题目链接:https://codeforces.com/contest/1105/problem/D 题意:p 个人在 n * m 的地图上扩展自己的城堡范围,每次最多走 a_i 步(曼哈顿距离),按 1 ~ p 的顺序,问最后每个人占领的点的数量. 题解:用一个队列维护当前起点,用另一个队列模拟当前起点走 a_i 步可以到达的全部点.(60 ~ 63行关键代码,多源bfs,不可分开跑) 数据: 4 3 2 2 1 1.. 1.. ..2 ... output:10 2 1 #include <

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 memory limit per test 256 megabytes input standard input output standard output Given a string ss of length nn and integer kk (1≤k≤n1≤k≤n). The string

Codeforces Round #533 (Div. 2)

A. Salem and Sticks 由于长度很小,所以直接暴力枚举最后的长度即可,取最小值即可. #include<bits/stdc++.h> #define CLR(a,b) memset(a,b,sizeof(a)); using namespace std; typedef long long ll; const int inf=0x3f3f3f3f; const int maxn=10010; int a[1100],n; int cost,ans; int main(){ ci

Codeforces Round #533 (Div. 2) Solution

A. Salem and Sticks 签. 1 #include <bits/stdc++.h> 2 using namespace std; 3 4 #define N 1010 5 int n, a[N]; 6 7 int work(int x) 8 { 9 int res = 0; 10 for (int i = 1; i <= n; ++i) 11 res += max(0, abs(x - a[i]) - 1); 12 return res; 13 } 14 15 int m

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

C. Ayoub and Lost Array Ayoub had an array ?? of integers of size ?? and this array had two interesting properties: All the integers in the array were between ?? and ?? (inclusive). The sum of all the elements was divisible by 3. Unfortunately, Ayoub

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

题目链接 A. Salem and Sticks 分析 暴力就行,题目给的n<=1000,ai<=100,暴力枚举t,t从2枚举到98,复杂度是1e5,完全可行. 代码 1 #include <cstdio> 2 #include <cmath> 3 #include <iostream> 4 #include <cstring> 5 #include <algorithm> 6 #include <vector> 7 #

Codeforces Round #118 (Div. 1) A Mushroom Scientists (多元函数极值问题+拉格朗日乘数法)

Codeforces Round #118 (Div. 1) A Mushroom Scientists 题意:提炼出来就是求f(x,y,z)=x^a*y^b*z^b,这个三元函数在(0 思路: 更严格的还要证明在边界所取到的值比极值要小. 注意:%.10lf注意看题目的output AC代码: #include int main(){ int s; ... meilijie.com/ask/view/377116/ meilijie.com/ask/view/377668/ meilijie.

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿