栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

poj 2989 All Friends

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

poj 2989 All Friends

#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <algorithm>#include <vector>using namespace std;#define SZ(v) ((int)(v).size())const int maxn = 128;int g[maxn+5][maxn+5],vis[maxn+5][maxn+5],com[maxn+5][maxn+5];int n,m,ans;void clique(int com_cnt,int vis_cnt,int dep){    if(!com_cnt){        if(!vis_cnt)    ans++;        return;    }    for(int i=1;i<=vis_cnt;i++){        bool found=false;        int t=vis[dep][i];        for(int j=1;j<=com_cnt;j++){ if(!g[t][com[dep][j]]){     found=true;     break; }        }        if(!found)  return;    }    for(int i=1;i<=com_cnt;i++){        int v=com[dep][i];        int t,t_com_cnt=0,t_vis_cnt=0;        for(int j=i+1;j<=com_cnt;j++){ t=com[dep][j]; if(g[v][t]) com[dep+1][++t_com_cnt]=t;        }        for(int j=1;j<=vis_cnt;j++){ t=vis[dep][j]; if(g[v][t]) vis[dep+1][++t_vis_cnt]=t;        }        if(ans>1000)    return;        clique(t_com_cnt,t_vis_cnt,dep+1);        vis[dep][++vis_cnt]=v;    }}int main() {    while(scanf("%d%d",&n,&m)==2){        memset(g,0,sizeof(g));        for(int i=1;i<=m;i++){ int u,v; scanf("%d%d",&u,&v); g[u][v]=g[v][u]=1;        }        ans=0;        for(int i=1;i<=n;i++)   com[1][i]=i;        clique(n,0,1);        if(ans>1000){ printf("Too many maximal sets of friends.n");        }        else{ printf("%dn",ans);        }    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/372040.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号