-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2407_조합.cpp
51 lines (44 loc) · 943 Bytes
/
2407_조합.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
#include <math.h>
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
string dp[102][102];
void bigIntAdd(string n1, string n2, int i, int j) {
int sum = 0;
while (sum || !n1.empty() || !n2.empty()) {
if (!n1.empty()) {
sum += n1.back() - '0';
n1.pop_back();
}
if (!n2.empty()) {
sum += n2.back() - '0';
n2.pop_back();
}
dp[i][j].push_back((sum % 10) + '0');
sum /= 10;
}
return;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= i; j++) {
if (j == 0 || j == i) {
dp[i][j] = "1";
} else {
string n1 = dp[i - 1][j - 1];
string n2 = dp[i - 1][j];
bigIntAdd(n1, n2, i, j);
reverse(dp[i][j].begin(), dp[i][j].end());
}
}
}
cout << dp[n][m];
return 0;
}