코딩 일지/baekjoon

1010-다리놓기(dp를 활용한 combination 구현)

훈감자 2023. 1. 24. 16:57

#include <bits/stdc++.h>
using namespace std;
#define INT unsigned long long int 
INT n,m,t,as;
INT ans;
INT memo[100][100];
INT f(INT x, INT y)
{
  if(x==0)  return 0;
  if(x==y || y==0)  return 1;
  if(memo[x][y])  return memo[x][y];
  memo[x][y] = f(x-1, y-1) + f(x-1, y);
  return memo[x][y];
}
int main()
{
  ios::sync_with_stdio(false);

  cin >> t;
  
  for(int j=0; j<t; j++)
  {
    as = 1;
n = m = 0; 
    cin >> n >> m;
    cout << f(m,n) << endl;
  }
  
return 0;
}