forked from KIET7UKE/HacktoberRepo-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBinomialCoefficientDp.cpp
111 lines (100 loc) · 3.25 KB
/
BinomialCoefficientDp.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fastio() ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define int long long
#define double long double
#define endl "\n"
#define v(x) vector<x>
#define pb push_back
#define all(s) s.begin(),s.end()
#define sz(x) (int)x.size()
#define f(i,n) for(int i = 0; i < n; ++i)
#define ff(i,n) for(int i = 1; i <= n; ++i)
#define frev(i,n) for(int i = n; i >= 0; --i)
#define rep(i, lo, hi, inc) for(int i=lo; i<=hi and inc>0 or i >= hi and inc<0; i+=inc)
#define input(x) for(auto &e:x)cin>>e
#define fa(x) for(auto it:x)
#define far(x) for(auto &it:x)
#define sci(x) int x; cin>>x
#define scii(x,y) int x,y; cin>>x>>y
#define sciii(x,y,z) int x,y,z; cin>>x>>y>>z
#define print(x) fa(x) cout<<it<<" ";cout<<"\n"
#define numberOfSetBits(x) __builtin_popcountll(x)
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
int MOD = 1e9 + 7, intmax = LLONG_MAX, intmin = LLONG_MIN;
int power(int x, int y, int p = MOD) { //gives x^y, logy time
int res = 1; x = x % p;
if (x == 0) return 0;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1; x = (x * x) % p;
}
return res;
}
int add(int x, int y, int mod = MOD) {return ( (x % mod) + (y % mod)) % mod;}
int subtract(int x, int y, int mod = MOD) {return ((x % mod) - (y % mod) + mod) % mod;}
int multiply(int x, int y, int mod = MOD) {return ( (x % mod) * (y % mod)) % mod;}
int divide(int x, int y, int mod = MOD) { //y and mod must be coprime,log(mod) time
x %= mod; y %= mod; int gcd = __gcd(x, y); x /= gcd; y /= gcd;
int yinverse = power(y, mod - 2, mod); return (x * yinverse) % mod;
}
v(int) factorial;
void computeFactorialTill(int maxn, int mod = MOD) {
factorial.assign(maxn + 1, 1);//call this fn in main, O(maxn) time
ff(i, maxn)
factorial[i] = (i * factorial[i - 1]) % mod;
}
int ncr(int n, int r, int mod = MOD) {
if (r > n - r) r = n - r; //O(maxn) time due to computing factorial
return divide(factorial[n], factorial[r] * factorial[n - r], mod);
}
void query(int a, int b) {
cout << "? " << a << ' ' << b << endl; cout.flush();
}
void print1d(v(int) a) {
fa(a)
cout << it << " ";
cout << endl;
}
void print2d(v(v(int)) &a) {
fa(a) {
print(it);
}
}
int maxn = 5000;
int C[maxn + 1][maxn + 1];
void binomialCoeff(int n = maxn, int k = maxn) //O(nk) time, call in main
{
int i, j;
// Calculate value of Binomial Coefficient
// in bottom up manner
for (i = 0; i <= n; i++) {
for (j = 0; j <= min(i, k); j++) {
// Base Cases
if (j == 0 || j == i)
C[i][j] = 1;
// Calculate value using previously
// stored values
else
C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;
}
}
}
void solve() {
}
signed main() {
fastio();
int t = 1;
cin >> t;
ff(i, t) {
// cout << "Case #" << i << ": \n";
solve();
}
return 0;
}