-
Notifications
You must be signed in to change notification settings - Fork 3
/
1-million-permutations-and-subsets.cpp
63 lines (52 loc) · 1.18 KB
/
1-million-permutations-and-subsets.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
/**
* @file basics.cpp
* @author prakash ([email protected])
* @brief
One million permutations means all arrangements of roughly 10 objects, but
not more. One million subsets means all combinations of roughly 20 items,
but not more.
example:
- permutation of { 1,2,3}
- {1,2,3}
- {2,3,1}
- {3,1,2}
- {2,1,3}
- {3,2,1}
- {1,3,2}
- subsets of { 1,2,3}
- {}
- {1}
- {2}
- {3}
- {1,2}
- {2,3}
- {1,2,3}
* @version 0.1
* @date 2021-07-27
*
* @copyright Copyright (c) 2021
*
*/
#include <assert.h>
#include <cmath>
#include <iostream>
using namespace std;
typedef long long int ll;
#define MAX 100
ll factorial_table[MAX];
ll permutation(ll n) {
if (n <= 1)
factorial_table[n] = 1;
factorial_table[1] = 1;
for (ll i = 2; i <= n; i++) {
factorial_table[i] = i * factorial_table[i - 1];
}
return factorial_table[n];
}
ll subsets(ll n) { return pow(2, n); }
int main(int argc, const char **argv) {
assert(permutation(10) >= pow(10, 6));
assert(subsets(20) >= pow(10, 6));
std::cout << "Assertion succeeded "<< std::endl;
return 0;
}