[Explanations] Luo Gu P4821 [Zhongshan election] Spanning Tree

Topic Portal

Subject description:
There is a graphic called a pentagonal ring.
Here Insert Picture Description
A circle with a center pentagon an n by n vertices and edges consisting ring. At the same time also a certain side of a pentagon, a total of n different in each of the n pentagonal rim midpoint of the side. The pentagon only common vertex on the center of the ring pentagon circle. FIG pentagonal ring is a 4- 0 FIG.
N now given a pentagonal ring, your task is the number of different spanning n pentagonal rings obtained. Remember what is the spanning tree do? It is a spanning tree diagram and the number of all the vertexes of the original reservation subtracting a plurality of such edge, thereby generating a tree.
Note: n pentagon in a given circle all the vertices are as different vertices.


Input format
input comprises a plurality of sets of test data.
The first line contains a positive integer T, represents the number of test data.
Each test contains an integer n (2 <= N <= 100), you need to solve the edge represents the number of turns of the center pentagon.


Output format
for each set of test data output line contains an integer x, denotes the number of spanning trees results after 2007 pentagonal ring modulo n.

Analysis:
a mathematical derivation problem ( w c wc is actually placed in graph theory, specifically about. . ).

  • We first consider the concept of spanning tree: n n FIG points are n 1 n-1 edges are attached.

Not difficult to draw, drawing a total of 4 n 4n points, 5 n 5n sides.

  • Depending on the nature of the spanning tree, we need to remove n 1 n-1 edges.

Shared equally down each side of a pentagon need to be deleted, leaving an edge. (That there is a need to delete the two sides of the pentagon)

Since the positive FIG. n n deformation is a ring, so we must have a positive side is the need to delete n n -sided polygon edges.

  • A pentagon need to delete the two sides, there is a positive side to be deleted n n -gon side, there are four ways, each pentagon may be deleted two sides of this pentagon, a total of n n a is 4 n 4n ways
  • The remaining n-1 each have five sides pentagons can be deleted, a total of 5 n 1 5^{n-1} kinds of programs

Therefore, the total number of programs are:
4 n   +   5 n 1 4*n\ +\ 5^{n-1}

Then the specific code as follows:

#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define P 2007
int t;
int main(){
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);
	scanf("%d",&t);
	while (t--){
	    int n;
	    scanf("%d",&n);
	    LL Pow=1;
	    for (int i=1;i<n;i++) Pow=(Pow*5)%P;
	    printf("%lld\n",(Pow*4*n)%P);
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}

Guess you like

Origin blog.csdn.net/huang_ke_hai/article/details/87918858