Test instructions
Figure out an N-point m-side graph to find the number of simple rings (no duplicate points and edges).
Ideas
This is a good question, this pressure DP save state is not a direct ring, but the number of paths. s represents a path, then Dp[s][i] indicates the number of rings with the minimum number of S as the starting point and I as the end point. Then we can determine whether the endpoint and the starting point are connected by enumerating the state, enumerating the starting point in the state and the end of the enumeration path.
Code
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <stack>#include <set>#include <map>#include <list>#include <string>#include <math.h>#include <stdlib.h>#include <time.h>using namespace STD;#define LL Long Long#define LOWBIT (x) ((x) & ( -X))#define Lson L, Mid, RT << 1#define Rson Mid + 1, R, RT << 1|1#define MP (A, B) Make_pair (A, b)Const intINF =0x3f3f3f3f;Const intMOD =1000000007;Const intMAXN =1e5+Ten;Const DoubleEPS =1e-8;Const DoublePI =ACOs(-1.0);typedefpair<int,int> PII; LL dp[1<< -][ -];BOOLa[ -][ -];intMain () {//freopen ("In.txt", "R", stdin); //freopen ("OUT.txt", "w", stdout); intN, M, U, v;Cin>> n >> m; for(inti =0; I < m; i++) {Cin>> u >> v; U--, v--; A[U][V] = A[v][u] =1; }memset(DP,0,sizeof(DP)); for(inti =0; I < n; i++) dp[1<<i][i] =1; LL ans =0; for(ints =1; S < (1<< N); s++) {intSt =0; for(inti =0; I < n; i++)if(S & (1<< i)) st = i, i = n; for(inte = st; e < n; e++)if(S & (1<< e)) for(inti = st; I < n; i++)if(! (S & (1<< i)) && A[e][i]) {dp[s| (1<<i)][i] + = dp[s][e];if(A[i][st] && __builtin_popcount (s| (1<<i)) >=3) ans + = dp[s][e]; } }cout<< ans/2<< Endl;return 0;}
Codeforces 11d-a Simple Task (pressure DP)