Give a graph of n points and a tree of n points, figure out the number of schemes corresponding to point one by one on the tree. (N<=17)
Ideas:
1. Tree Dp,f[i][j on the structure of trees] indicates the number of sub-trees in the tree where point I corresponds to the point J on the graph. O (n^3).
2. We can find that the "one by one correspondence" relationship is difficult to guarantee if the DP is defined by this definition. If the entire array is given a corresponding relationship, then C (n,n) =n! Can only get violent points, then we do not limit the "one by one correspondence" and instead of "one-to-many" relationship to the tree DP, the use of the principle of tolerance to O (2^n) complexity. (P.S. As to why the principle of repulsion is not clear to me, I will update it after I understand it.) )
3. The application of the principle of repulsion is this: using a binary number to enumerate the number of times each DP has no corresponding points on the tree, the sum of the DP scheme in all cases and the formula for the complement set is the answer to "all the numbers correspond to the points on the tree."
The circle 1 indicates that number 1 has no corresponding point scheme number, and so on. The color section is the complement we require.
The following code is attached--
1#include <cstdio>2#include <cstdlib>3#include <cstring>4#include <iostream>5 using namespacestd;6 7typedefLong LongLL;8 Const intn= -, m= -;9 structnode{intX,y,next;} a[2*N];Ten intLast[n],len; One BOOLV[n][n],vis[n]; A LL F[n][n]; - intB[N],BT; - the voidAddintXinty) - { -len++; -a[len].x=x,a[len].y=y; +a[len].next=last[x],last[x]=Len; - } + A voidDfsintXintFA) at { - /*for (int k=last[x];k;k=a[k].next) - { - int y=a[k].y; - if (Y==FA) continue; - DFS (y,x); in } - for (int kk=1;kk<=bt;kk++) to { + int I=B[KK]; - f[x][i]=1; the for (int k=last[x];k;k=a[k].next) * { $ int y=a[k].y;Panax Notoginseng if (Y==FA) continue; - LL h=0; the for (int kkk=1;kkk<=bt;kkk++) + { A int J=B[KKK]; the if (V[i][j]) h+=f[y][j]; + } - f[x][i]*=h; $ } $ }*///Side build , side not repeat DP - if(Vis[x])return; - for(intkk=1; kk<=bt;kk++) the { - intI=B[KK];Wuyif[x][i]=1; the for(intk=last[x];k;k=a[k].next) - { Wu inty=a[k].y; - if(Y==FA)Continue; About DFS (y,x); $vis[y]=true; -LL h=0; - for(intkkk=1; kkk<=bt;kkk++) - { A intj=B[KKK]; + if(V[i][j]) h+=F[y][j]; the } -f[x][i]*=h; $ } the}//mark it up! the } the the intMain () - { in intn,m; thescanf"%d%d",&n,&m); thememset (V,false,sizeof(v)); About for(intI=1; i<=m;i++) the { the intx, y; thescanf"%d%d",&x,&y); +v[x][y]=v[y][x]=true; - } theMemset (Last,0,sizeof(last));Bayilen=0; the for(intI=1; i<n;i++) the { - intx, y; -scanf"%d%d",&x,&y); the Add (x, y), add (y,x); the } theLL ans=0; the for(intI=1;i< (1<<N); i++) - { thebt=0; the for(intj=1; j<=n;j++) the if(i& (1<< (J-1)) b[++bt]=J;94memset (Vis,false,sizeof(Vis)); theDfs1,0); theLL h=0; the for(intj=1; j<=bt;j++)98h+=f[1][b[j]]; About if((N-BT)%2==0) Ans+=h;//by complement set - Elseans-=h;101 }102printf"%lld\n", ans);103 return 0;104}
"Bzoj 4455" small star (tree-type dp+-tolerant principle)