"HDOJ5952" Counting cliques (group, DFS)

Source: Internet
Author: User
Tags cas

Test instructions: Given a graph of n-point m edges, the number of clusters of size s

N≤100,M≤1000,2≤S≤10, no more than 20 of the guaranteed points

Idea: DFS

Because each point may not belong to more than one great regiment, it is not possible to find the maximal regiment and then count

DFS searches all legitimate scenarios, searching only for all the points that are incremented, so there is no problem of repeating the count.

It's also a common technique to avoid repetition counting.

1#include <cstdio>2#include <cstring>3#include <string>4#include <cmath>5#include <iostream>6#include <algorithm>7#include <map>8#include <Set>9#include <queue>Ten#include <vector> One#include <bits/stdc++.h> A using namespacestd; -typedefLong Longll; -typedef unsignedint UINT; thetypedef unsignedLong Longull; -typedef pair<int,int>PII; -typedef vector<int>VI; - #defineFi first + #defineSe Second - #defineMP Make_pair + #defineN 110 A #defineM 2100 at #defineMOD 1000000007 - #defineEPS 1e-8 - #definePi ACOs (-1) -  - intF[n][n],head[m],vet[m],nxt[m],c[n],n,m,s,tot,ans; -  in intRead () - {  to    intv=0, f=1; +    CharC=GetChar (); -     while(c< -|| $&LT;C) {if(c=='-') f=-1; C=GetChar ();} the     while( -<=c&&c<= $) v= (v<<3) +v+v+c- -, c=GetChar (); *    returnv*F; $ }Panax Notoginseng  - voidAddintAintb) the { +nxt[++tot]=Head[a]; Avet[tot]=b; thehead[a]=tot; + } -  $ voidDfsintKintu) $ { -     //for (int i=1;i<=k;i++) printf ("%d", C[i]); -     //printf ("\ n"); the     if(k==s) -     {Wuyians++; the         return; -     } Wu     intE=Head[u]; -      while(e) About     { $         intv=Vet[e]; -         if(V<u) {E=nxt[e];Continue;} -         intflag=1; -          for(intI=1; i<=k;i++) A          if(!f[c[i]][v]) {flag=0; Break;} +         if(flag) the         { -c[k+1]=v; $DFS (k +1, v); thec[k+1]=0; the         } theE=Nxt[e]; the     } - } in              the          the intMain () About { theFreopen ("hdoj5952.in","R", stdin); theFreopen ("Hdoj5952.out","W", stdout); the     intCAs; +scanf"%d",&CAs); -      while(cas--) the     {Bayiscanf"%d%d%d",&n,&m,&s); the          for(intI=1; i<=n;i++) head[i]=0; the          for(intI=1; i<=n;i++) -           for(intj=1; j<=n;j++) f[i][j]=0; -tot=0; the          for(intI=1; i<=m;i++)  the         { the             intx, y; thescanf"%d%d",&x,&y); - Add (x, y); the Add (y,x); thef[x][y]=f[y][x]=1; the         }94ans=0; the          for(intI=1; i<=n;i++)  the         { thec[1]=i;98Dfs1, i); Aboutc[1]=0; -         }101printf"%d\n", ans);102     }103     return 0;104 } the      

"HDOJ5952" Counting cliques (group, DFS)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.