zoukankan      html  css  js  c++  java
  • 状态压缩codeforces 11 D

    n个点m条边

    m条边

    求有几个环;

    #pragma comment(linker, "/STACK:102400000,102400000")  
    #include <iostream>  
    #include <cstdio>  
    #include <cstring>  
    #include <string>  
    #include <vector>  
    #include <algorithm>  
    #include <queue>  
    #include <set>  
    #include <map>  
    using namespace std;  
      
    typedef long long LL;  
    typedef pair<int,int> PII;  
      
    const int N=20;  
      
    LL ans;  
    int n,m,low;  
    LL dp[600000][N];  
    bool adj[N][N];  
      
      
    int main()  
    {  
        scanf("%d%d",&n,&m);  
      
        for(int i=0;i<m;i++)  
        {  
            int a,b; scanf("%d%d",&a,&b);  
            a--; b--;  
            adj[a][b]=adj[b][a]=1;  
        }  
      
        for(int i=0;i<n;i++) dp[1<<i][i]=1;  
      
        for(int i=1;i<(1<<n);i++)  
        {  
            int st=n+1,cnt=0;  
            for(int j=0;j<n;j++)        //这个状态中有多少个点 
         if(i&(1<<j)) { st=min(st,j); cnt++; } for(int j=0;j<n;j++)
       if(dp[i][j]) { if(adj[j][st]&&cnt>=3) //点>=三 又要能回去 { ans+=dp[i][j]; } for(int k=0;k<n;k++)
            if(adj[j][k]&&k>st) //st是最小的点 { if((i&(1<<k))==0) dp[i^(1<<k)][k]+=dp[i][j]; } } } cout<<ans/2<<endl; return 0; }
  • 相关阅读:
    java ,js获取web工程路径
    js 无刷新分页代码
    js 获取时间对象代码
    jquery 文本框失去焦点显示提示信息&&单击置空文本框
    CodeForces
    nth_element() O(n)复杂度求第k+1小元素
    CodeForces
    HDU
    杜教BM
    J
  • 原文地址:https://www.cnblogs.com/cherryMJY/p/6142306.html
Copyright © 2011-2022 走看看