Skip to content

Commit

Permalink
2024-07-28 부녀회장이 될테야
Browse files Browse the repository at this point in the history
  • Loading branch information
oesnuj committed Jul 27, 2024
1 parent fc20d42 commit 2b4a619
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
53 changes: 53 additions & 0 deletions oesnuj/DP/2775.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*풀이1 재귀만 이용*/
//#include <iostream>
//using namespace std;
//
//int calc(int k, int n) {
// if (k == 0) return n;
// int sum = 0;
// for (int i = n; i > 0; i--) {
// sum += calc(k - 1, i);
// }
// return sum;
//}
//
//int main()
//{
// int T, k, n;
// cin >> T;
// while (T--) {
// cin >> k >> n;
// cout << calc(k, n) << "\n";
// }
// return 0;
//}

/*풀이2, 재귀 + DP*/
#include <iostream>
#include <vector>
using namespace std;

vector<vector<int>> dp;

int calc(int k, int n) {
if (k == 0) return n;
if (dp[k][n] != -1) return dp[k][n]; // 이미 계산된 값이면 반환

int sum = 0;
for (int i = n; i > 0; i--) {
sum += calc(k - 1, i);
}
return dp[k][n] = sum; // 계산된 값을 저장하고 반환
}

int main()
{
int T, k, n;
cin >> T;
while (T--) {
cin >> k >> n;
dp = vector<vector<int>>(k + 1, vector<int>(n + 1, -1)); //케이스별 DP 테이블 초기화
cout << calc(k, n) << "\n";
}
return 0;
}
1 change: 1 addition & 0 deletions oesnuj/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
| 10차시 | 2024.07.04 | 구현 | [상어초등학교](https://www.acmicpc.net/problem/21608) | [#34](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/34) |
| 11차시 | 2024.07.18 | 이분 탐색 | [랜선 자르기](https://www.acmicpc.net/problem/1654) | [#38](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/38) |
| 12차시 | 2024.07.24 | 재귀 | [하노이 탑](https://www.acmicpc.net/problem/1914) | [#41](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/41) |
| 13차시 | 2024.07.28 | DP | [부녀회장이 될테야](https://www.acmicpc.net/problem/2775) | [#44](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/44) |
---

0 comments on commit 2b4a619

Please sign in to comment.