백준
백준 소스코드 [C++] 1010 다리 놓기
Hani_Levenshtein
2020. 9. 7. 23:17
1010번: 다리 놓기
입력의 첫 줄에는 테스트 케이스의 개수 T가 주어진다. 그 다음 줄부터 각각의 테스트케이스에 대해 강의 서쪽과 동쪽에 있는 사이트의 개수 정수 N, M (0 < N ≤ M < 30)이 주어진다.
www.acmicpc.net
백준 소스코드 [C++] 1010 다리 놓기
#include <iostream>
#include <algorithm>
#include <queue>
#include <string.h>
#include <limits.h>
#include <vector>
#include <math.h>
#include <stack>
#include <bitset>
#include <string>
#include <set>
#define all(v) v.begin(), v.end()
#define pii pair<int,int>
#define make_unique(v) v.erase(unique(v.begin(), v.end()), v.end())
typedef long long ll;
using namespace std;
int arr[29][30] = { 0 };
int num(int L, int R) {
if (L == R) return 1;
else if (L == 1) return R;
else if (arr[L][R] != 0) return arr[L][R];
else {
arr[L][R]=num(L - 1, R - 1) + num(L, R - 1);
return arr[L][R];
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
int left, right;
while (n--) {
cin >> left >> right;
cout << num(left, right) << '\n';
}
return 0;
}