CCPC长春 G Instability

Instability

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0

Problem Description
Long long ago, there was a prosperous kingdom which consisted of n cities and every two cites were connected by an undirected road.

However, one day a big monster attacked the kingdom and some roads were destroyed. In order to evaluate the influence brought by the catastrophe, the king wanted to know the instability of his kingdom. Instability is defined as the number of the unstable subset of {1, 2,⋯,n}.

A set S is unstable if and only if there exists a set A such that A⊆S(|A|≥3) and A is a clique or an independent set, namely that cites in A are pairwise connected directly or they are pairwise disconnected.

Archaeologist has already restored themroads that were not destroyed by the monster. And they want you to figure out the instability.

Since the answer may be tremendously huge, you are only required to write a program that prints the answer modulo 1000000007.

Input
The first line contains only one integer T, which indicates the number of test cases.

For each test case, the first line contains two integers n (3≤n≤50) and m (1≤m≤n(n−1)/2), indicating the number of cities and the number of roads.

Then the following are m lines, each of which contains two integers x and y, indicating there is a road between the city x and the city y.

It is guarenteed that there does not exist a road connecting the same city and there does not exist two same roads.

Output
For each test case, print a line “Case #x: y”, where x is the case number (starting from 1) and y is an integer indicating the instability modulo 1000000007.

Sample Input
2
4 3
1 2
2 3
1 3
3 0

Sample Output
Case #1: 2
Case #2: 1

Hint

• In the first example, {1,2,3} and {1,2,3,4} , containing the subset {1,2,3} which is connected
directly, are considered unstable.
• In the second example, {1,2,3} is considered unstable because they are not pairwise connected
directly.

题意:给50个点,求满足有三元完全子图的集合个数。
做法:Ramsey定理,G6->G3,所以6元及以上集合必然有三元完全子图。只需暴力跑一遍5元集以下的正确性就ok了,复杂度C(50,5),正好够。

代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
int g[105][105];
int rec[10];
int n, m;
ll ans;
ll power(ll x, ll y)
{
    ll base=x;
    ll ans=1;
    while(y>0)
    {
        if(y&1)ans=(ans*base)%mod;
        y>>=1;
        base=(base*base)%mod;
    }
    return ans;
}

ll niyuan(ll x)
{
    return power(x, mod-2);
}

ll C(ll m, ll n)
{
    ll ans=1;
    for(ll i=1;i<=n;i++)
    {
        ans=ans*(m-n+i)%mod;
        ans=ans*niyuan(i)%mod;
    }
    return ans;
}

void dfs(int flor, int last){
    if (flor==6) return ;
    for (int i=last+1;i<=n;i++){
        rec[flor]=i;
        if (flor>=3){
            bool ok=false;
            for (int p1=1;p1<flor-1;p1++){
                for (int p2=p1+1;p2<flor;p2++){
                    for (int p3=p2+1;p3<=flor;p3++){
                        if (g[rec[p3]][rec[p1]] && g[rec[p3]][rec[p2]] && g[rec[p1]][rec[p2]])
                        {
                            ans++;ok=true;break;
                        }
                        else if (!g[rec[p3]][rec[p1]] && !g[rec[p3]][rec[p2]] && !g[rec[p1]][rec[p2]])
                        {
                            ans++;ok=true;break;
                        }
                    }
                    if(ok)break;
                }
                if(ok)break;
            }
        }
        dfs(flor+1, i);
    }
}

int main()
{
    int t;
    scanf("%d", &t);
    for(int tt=1;tt<=t;tt++)
    {
        scanf("%d%d", &n, &m);
        memset(g, 0, sizeof(g));
        int x, y;
        for(int i=1;i<=m;i++)
        {
            scanf("%d%d", &x, &y);
            g[x][y]=g[y][x]=1;
        }
        ans=power(2, n);
        for(ll i=0;i<=5;i++)
            ans=(ans-C(n, i)+mod)%mod;
        //printf("%lld\n", ans);

        //printf("%lld\n", ans);
        dfs(1, 0);
        printf("Case #%d: %lld\n", tt, ans%mod);
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值