GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — code-library/Math/Permanent of a Matrix.cpp at master · SuckSolace/code-library

Expand file tree

/

Permanent of a Matrix.cpp

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
26 lines (24 loc) · 657 Bytes
/

Permanent of a Matrix.cpp

Copy path

File metadata and controls

26 lines (24 loc) · 657 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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.