UvaLive 6600 Spanning trees in a secure lock pattern 矩阵行列式
2017-08-21 21:02
375 查看
这是去年尝试过得题目。今年还是不会。只能先搬大佬题解过来。来自:http://blog.csdn.net/ooooooooe/article/details/38899517
题意:给一个N*N个点的矩阵(N<=6),每个点只能和周围八个点相连,问有多少种生成树的方式。
思路:题里给的很明白,就是列一个每个点的边的矩阵,然后求子矩阵的行列式就可以了,因为N只有6,所以打表就可以了。
打表代码:
AC代码:
int main()
{
char ss[10][40]={"1","16","17745","1064918960","3271331573452806","504061943351319050000000"};
int T;
scanf("%d",&T);
while(T--)
{
int a;
scanf("%d",&a);
puts(ss[a-1]);
}
}
题意:给一个N*N个点的矩阵(N<=6),每个点只能和周围八个点相连,问有多少种生成树的方式。
思路:题里给的很明白,就是列一个每个点的边的矩阵,然后求子矩阵的行列式就可以了,因为N只有6,所以打表就可以了。
打表代码:
#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 long LL; typedef unsigned long long ULL; using namespace std; #define MOD 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; A.build(t); printf("%.0f\n",A.det()); return 0; }
AC代码:
int main()
{
char ss[10][40]={"1","16","17745","1064918960","3271331573452806","504061943351319050000000"};
int T;
scanf("%d",&T);
while(T--)
{
int a;
scanf("%d",&a);
puts(ss[a-1]);
}
}
相关文章推荐
- UvaLive 6600 Spanning trees in a secure lock pattern 矩阵行列式
- UvaLive 6600 Spanning trees in a secure lock pattern 矩阵行列式
- uvalive 6600 - Spanning trees in a secure lock pattern
- UVALive 7003 A Balance Game on Trees(树形dp)
- UVALive 3695 Distant Galaxy 用矩阵的边覆盖二维平面上最多的点 科学的枚举
- UVAlive 3662 Another Minimum Spanning Tree 莫队算法,曼哈顿最小生成树
- UVaLive 7361 Immortal Porpoises (矩阵快速幂)
- UVALive 4221 Walk in the Park 扫描线
- 【UVALive】2145 - Lost in Space(数学)
- UVALive 7267 Mysterious Antiques in Sackler Museum 思维题 拼接矩形
- UVALive 7361(矩阵快速幂)
- UVALive 6092 Catching Shade in Flatland
- UVALive 7267 Mysterious Antiques in Sackler Museum (判断长方形)
- UVALive 7139-Rotation-前缀矩阵
- UVALive - 2728 A Spy in the Metro DP
- UVALive 6465 Islands in the Data Stream 暴力模拟
- UVA 10214 - Trees in a Wood.
- Trees in a Wood. UVA - 10214 欧拉函数表
- Trees in a Wood. UVA - 10214
- UVALive 6184_One-Dimensional Cellular Automaton(矩阵快速幂)