-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from AlgoLeadMe/13-oesnuj
13-oesnuj
- Loading branch information
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters