문제
코드
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, dp[31][31];
ll go(ll all, ll half)
{
if (all == 0 && half == 0)
return 1;
if (dp[all][half])
return dp[all][half];
ll& ret = dp[all][half];
if (all > 0)
ret += go(all - 1, half + 1);
if (half > 0)
ret += go(all, half - 1);
return ret;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
while (true)
{
cin >> n;
if (n == 0)
break;
cout << go(n, 0) << "\n";
}
return 0;
}
'개발 > 알고리즘' 카테고리의 다른 글
백준 4781번 사탕가게 C++ (0) | 2021.04.16 |
---|---|
백준 2470 두 용액 C++ (0) | 2021.04.13 |
백준 15651 N과M(3) - 중복 순열 C++ (0) | 2021.04.11 |
백준 15650 N과M(2) - 조합 C++ (0) | 2021.04.11 |
백준 15649 N과M(1) - 순열 C++ (0) | 2021.04.10 |