-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1.cpp
96 lines (89 loc) · 1.23 KB
/
1.cpp
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int n = 3;
int m = 6;
int z[6][3];
int against(int a[]);
int fac(int a);
void perm(int a[], int p, int q);
void swap(int a[], int i, int j);
/*
int main()
{
int a[3][3];
int d[3];
for (int i = 0; i < n; ++i)
{
d[i] = i;
}
cout << "Please Input A Matrix : " << endl;
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
{
cin >> a[i][j];
}
perm(d, 0, n - 1);
int s;
int m = 0;
for (int i = 0; i < fac(n); ++i)
{
s = 1;
for (int j = 0; j < n; ++j)
{
s *= a[j][z[i][j]];
}
m += pow(-1, against(z[i])) * s;
}
cout << "The Value of Det is : " << m << endl;
return 0;
}
*/
int fac(int a)
{
int s = 1;
for (; a >= 1; a--)
s = s * a;
return s;
}
int against(int a[])
{
int c = 0;
for (int i = 0; i < n; ++i)
{
for (int j = i + 1; j < n; ++j)
{
if (a[i] > a[j])
++c;
}
}
return c;
}
void swap(int a[], int i, int j)
{
int temp;
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
void perm(int a[], int p, int q)
{
static int g = 0;
if (p == q)
{
for (int i = 0; i < n; ++i)
{
z[g][i] = a[i];
}
++g;
}
else {
for (int i = p; i <= q; ++i)
{
swap(a, p, i);
perm(a, p + 1, q);
swap(a, p, i);
}
}
}