File tree Expand file tree Collapse file tree 1 file changed +5
-49
lines changed Expand file tree Collapse file tree 1 file changed +5
-49
lines changed Original file line number Diff line number Diff line change 1
1
#include < bits/stdc++.h>
2
2
3
- template <uint64_t MOD = std::numeric_limits<uint64_t >::max()>
4
- class CombinationPascal {
5
- size_t N;
6
- std::vector<std::vector<uint64_t >> comb;
7
-
8
- public:
9
- // Time: O(N^2)
10
- CombinationPascal (
11
- size_t const N = 1000
12
- )
13
- {
14
- build (N);
15
- }
16
- // Time: O(N^2)
17
- void build (size_t const N) {
18
- this ->N = N;
19
- comb.assign (N + 1 , std::vector<uint64_t >(N + 1 , 0 ));
20
- comb[0 ][0 ] = 1 ;
21
- for (size_t n = 1 ; n <= N; ++n) {
22
- comb[n][0 ] = 1 ;
23
- for (size_t k = 1 ; k <= N; ++k) {
24
- comb[n][k] = (comb[n-1 ][k-1 ] + comb[n-1 ][k]) % MOD;
25
- }
26
- }
27
- }
28
- // nCk
29
- // n = [0,N], k = [0,n]
30
- // Time: O(1)
31
- uint64_t C (size_t const n, size_t const k) const {
32
- if (k > n) throw std::out_of_range (" k" );
33
- if (n > N) throw std::out_of_range (" n" );
34
- return comb[n][k];
35
- }
36
- // nHk
37
- // H(n,k) = C(n+k-1,k)
38
- // n = [0,N-k+1], k = [0,N]
39
- // Time: O(1)
40
- uint64_t H (size_t const n, size_t const k) const {
41
- if (n == 0 && k == 0 ) return 1 ;
42
- return C (n+k-1 ,k);
43
- }
44
- // Time: O(1)
45
- size_t size () const {
46
- return N;
47
- }
48
- };
49
-
50
3
using namespace std ;
51
4
using ll = int64_t ;
52
5
using ff = long double ;
@@ -58,8 +11,11 @@ int main() {
58
11
int L;
59
12
cin >> L;
60
13
61
- CombinationPascal<> solver (300 );
62
- ll ans = solver.H (12 , L-12 );
14
+ ll ans = 1 ;
15
+ for (int i = 1 ; i <= 11 ; ++i) {
16
+ ans *= L- i;
17
+ ans /= i;
18
+ }
63
19
cout << ans << endl;
64
20
65
21
return 0 ;
You can’t perform that action at this time.
0 commit comments