Uvalive 6600 spanning trees in a secure lock pattern matrix

Source: Internet
Author: User

Link: https://icpcarchive.ecs.baylor.edu/index.php? Option = com_onlinejudge & Itemid = 8 & page = show_problem & problem = 4611

Question: Give a matrix of N * n vertices (n <= 6). Each vertex can only be connected to eight neighboring vertices and ask how many tree generation methods are available.

Idea: The question is very clear, that is, to list a matrix of the edge of each vertex, and then obtain the determinant of the submatrix. Because N is only 6, you can create a table.

Code for table creation:

# Include <algorithm> # include <cmath> # include <cstdio> # include <cstdlib> # include <cstring> # include <ctime> # include <ctype. h> # include <iostream> # include <map> # include <queue> # include <set> # include <stack> # include <string> # include <vector> # define EPS 1e-8 # define INF 0x7fffffff # define PI ACOs (-1.0) # define seed 31 // 131,1313 typedef long ll; typedef unsigned long ull; using namespace STD; # define m Od 1000 # define maxn 40 # define maxm 40 struct matrix {int n, m; Double A [maxn] [maxm]; void change (int c, int D) {n = C; M = D; For (INT I = 0; I <n; I ++) for (Int J = 0; j <m; j ++) A [I] [J] = 0;} void copy (const Matrix & X) {n = x. n; M = x. m; For (INT I = 0; I <n; I ++) for (Int J = 0; j <m; j ++) A [I] [J] = x. A [I] [J];} void build (int n) {change (N * n, n * n); For (INT I = 0; I <n * N; I ++) {if (I % n! = 0) {A [I] [I-1] =-1; A [I-1] [I] =-1; A [I] [I] ++; A [I-1] [I-1] ++;} if (I % n! = 0 & I/n! = 0) {A [I] [i-n-1] =-1; A [i-n-1] [I] =-1; A [I] [I] ++; A [i-n-1] [i-n-1] ++;} if (I % n! = 0 & I/n! = N-1) {A [I] [I + n-1] =-1; A [I + n-1] [I] =-1; A [I] [I] ++; A [I + n-1] [I + n-1] ++;} If (I/n! = N-1) {A [I] [I + N] =-1; A [I + N] [I] =-1; A [I] [I] ++; A [I + N] [I + N] ++ ;}} double det () {for (INT I = 1; I <n; I ++) {for (Int J = 0; j <I; j ++) if (a [I] [J]! = 0) {for (int K = J + 1; k <m; k ++) A [I] [k]-= (a [J] [k] * A [I] [J]/A [J] [J]); A [I] [J] = 0 ;}} double ans = 1; for (INT I = 0; I <n-1; I ++) ans * = A [I] [I]; return ans ;}}; int main () {int t; scanf ("% d", & T); matrix; a. build (t); printf ("%. 0f \ n ",. det (); Return 0 ;}
AC code:

 
Int main () {char ss [10] [40] = {"1", "16", "17745", "1064918960", "3271331573452806", "504061943351319050000000 "}; int t; scanf ("% d", & T); While (t --) {int A; scanf ("% d", & ); puts (ss [A-1]);}


Uvalive 6600 spanning trees in a secure lock pattern matrix

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.