Geometric Patterns
Time limit1sMemory limit128 MB
For each given n, print the numbers of spanning trees of the 2 by n rectangular grid and the 2 by n circular grid modulo 10007.
- Level
Medium7 of 10
- Topics
- Combinatorics, Dynamic programming, Math
- Solved
- No attempts yet
Problem
People have decorated objects and buildings since prehistoric times. The most important element in that decoration is the geometric pattern, and geometric patterns are easy to spot in everyday life.
Suhwan, an expert in computational geometry, found that geometric patterns are built with great precision on grids and on their subgrids. He recently started a research project that generates geometric patterns automatically.
The grids Suhwan cares about are the rectangular grid and the circular grid. An rectangular grid is a graph whose vertices and edges form a rectangular lattice in the plane. Each row holds vertices and each column holds vertices. Its vertex set is and its edge set is . An circular grid is the rectangular grid with extra edges that wrap it around: for every , the edge is added.
Many geometric patterns form a spanning tree of the grid. A spanning tree is a subgraph that contains every vertex and some of the edges, has no cycle, and is connected. Suhwan wants to count the distinct spanning trees of a grid. Every vertex is distinguishable, so two spanning trees that coincide under a rotation or a reflection still count separately when their edge sets differ.
Given , write a program that counts the spanning trees of the rectangular grid and the spanning trees of the circular grid.
Input
The first line contains the number of test cases . Each of the following lines contains one integer . ()
Output
For each test case, print modulo and modulo on one line, separated by a single space. is the number of spanning trees of the rectangular grid, and is the number of spanning trees of the circular grid.