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< -|| $<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)