GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — code-library/Math/Permanent of a Matrix.cpp at master · SuckSolace/code-library Expand file tree/ Copy pathPermanent of a Matrix.cppMore file actions 26 lines (24 loc) · 657 Bytes / Copy pathPermanent of a Matrix.cppFile metadata and controls26 lines (24 loc) · 657 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 #include<bits/stdc++.h> using namespace std; const int N = 20; long long dp[1 << N]; int n, a[N][N]; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { cin >> n; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) cin >> a[i][j]; } memset(dp, 0, sizeof dp); dp[(1 << n) - 1] = 1; for (int mask = (1 << n) - 2; mask >= 0; mask--) { int i = __builtin_popcount(mask); for (int j = 0; j < n; j++) if (!(mask >> j & 1)) dp[mask] += dp[mask | 1 << j] * a[i][j]; } cout << dp[0] << '\n'; // permanent of the matrix } return 0; } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |