티스토리 뷰
2407번: 조합
n과 m이 주어진다. (5 ≤ n ≤ 100, 5 ≤ m ≤ 100, m ≤ n)
www.acmicpc.net
백준 소스코드 [C++] 2407 조합
#include <iostream>
#include <algorithm>
#include <queue>
#include <string.h>
#include <limits.h>
#include <vector>
#include <math.h>
#include <stack>
#include <bitset>
#include <string>
typedef long long ll;
using namespace std;
string arr[101][101];
string bigadd(string a, string b) {
string c;
int as, bs;
int bit = 0;
while (!a.empty() && !b.empty()) {
as = a.back() - '0'; bs = b.back() - '0';
c = (char)(((as + bs + bit) % 10) + '0') + c;
bit = (as + bs + bit) / 10;
a.pop_back();b.pop_back();
}
while (!a.empty()) {
as = a.back() - '0';
c = (char)(((as + bit) % 10) + '0') + c;
bit = (as + bit) / 10;
a.pop_back();
}
while (!b.empty()) {
bs = b.back() - '0';
c = (char)(((bs + bit) % 10) + '0') + c;
bit = (bs + bit) / 10;
b.pop_back();
}
if (bit == 1)c = (char)(bit + '0') + c;
return c;
}
string combination(int n, int m) {
if (arr[n][m]!="") return arr[n][m];
else return arr[n][m]=bigadd(combination(n - 1, m - 1), combination(n - 1, m));
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
for (int i = 1;i <= 100;i++)arr[i][i]=arr[i][0] = '1';
cout << combination(n, m);
return 0;
}
'백준' 카테고리의 다른 글
백준 소스코드 [C++] 10826 피보나치 수 4 (0) | 2020.10.30 |
---|---|
백준 소스코드 [C++] 10757 큰 수 A+B (0) | 2020.10.29 |
백준 소스코드 [C++] 15663 N과 M 9 (0) | 2020.10.29 |
백준 소스코드 [C++] 9465 스티커 (0) | 2020.10.29 |
백준 소스코드 [C++] 15989 1, 2, 3 더하기 4 (0) | 2020.10.28 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- 벨만포드 시간복잡도
- 에드몬드 카프 알고리즘
- WWDC21
- MeTal
- rxswift
- 강한 순환 참조
- WWDC17
- 네트워크 유량
- 최단경로 알고리즘
- 다익스트라 시간복잡도
- 벨만포드 알고리즘
- CPU와 Memory
- 최대 매칭
- Testable
- mach-o
- CompositionalLayout
- HIG
- 포드 풀커슨 알고리즘
- 컴퓨터 추상화
- 부스트캠프 6기
- test coverage
- 최단경로문제
- observeOn
- State Restoration
- WWDC19
- WWDC16
- 네트워크 플로우
- IOS
- 최단경로 문제
- 코딩대회
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함