Skip to content

Commit

Permalink
Merge pull request #44 from AlgoLeadMe/13-oesnuj
Browse files Browse the repository at this point in the history
13-oesnuj
  • Loading branch information
oesnuj authored Sep 4, 2024
2 parents 15e0658 + ca505a7 commit d407fd5
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 d407fd5

Please sign in to comment.