1.1 Problem Description
1.2 Problem Analysis
This paper mainly examines the method of generating tree and combinatorial mathematics in graph theory. By observing we can find that when the input is n, we have a total of (5*n-n) =4n points. By thinking we can know that in order to obtain a spanning tree, we must break all the five-horned rings. Then we can think about:
If, for a five-point shape, each of its edges is not deleted, then we can see that this must not constitute a spanning tree, because this causes any two points in the Pentagon to have at least two paths that do not conform to the meaning of the spanning tree. So we can draw the following conclusions:
(1) for the loop with the number of sides N, we can find a total of 4n points, a total of 5n edges. Based on the definition of the spanning tree, we can find that the spanning tree has a total of 4n-1 edges. Then we need to delete the n+1 edge.
(2) For each of the five corners, we need to delete at least one edge, because if we do not delete then we can find that for any two points of the Pentagon we can find at least two paths to each other. So we need to n-1 a five-point shape only need to delete an edge (there are 5 methods at this time). You need to delete two edges for the last five-point shape.
(3) for the need to delete two sides of the five-point shape, we can think, if the deletion is not a loop edge, then the end will certainly cause some of the points are not in the spanning tree, so we can derive from this, delete the two edges one of the non-loop edge, the other is the loop edge. Then there are 4 ways to delete this.
In this analysis, we can conclude that all the methods are: the methods of the species.
1.3AC Code
#include <iostream>using namespacestd;#defineMoD 2007intMain () {intN; while(cin>>N) {intsum=0; Sum=4*n%MoD; for(intI=1; i<=n-1; i++) Sum=sum*5%MoD; cout<<sum%mod<<Endl; } return 0;} Supplementary: For a large number of queries but with a small number of different queries, you can pre-process (play the table). This is faster and more efficient, so we can write a function like this, and then call the result directly:intANS[MAXN];voidprocess () { for(intI=2; i<=maxn;i++) {Ans[i]=4*i%MoD; for(intj=1; i<i;j++) Ans[i]=ans[i]*5%MoD; }}
Zhongshan University Team Tryouts Chapter 1 "Calculation Spanning tree"------January 23, 2015