From 2b4a619cd5bda910b4d891368b95ed6f45a71c2c Mon Sep 17 00:00:00 2001 From: Junseo Kim Date: Sun, 28 Jul 2024 03:42:50 +0900 Subject: [PATCH 1/3] =?UTF-8?q?2024-07-28=20=EB=B6=80=EB=85=80=ED=9A=8C?= =?UTF-8?q?=EC=9E=A5=EC=9D=B4=20=EB=90=A0=ED=85=8C=EC=95=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oesnuj/DP/2775.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++++++ oesnuj/README.md | 1 + 2 files changed, 54 insertions(+) create mode 100644 oesnuj/DP/2775.cpp diff --git a/oesnuj/DP/2775.cpp b/oesnuj/DP/2775.cpp new file mode 100644 index 0000000..c7cf2e6 --- /dev/null +++ b/oesnuj/DP/2775.cpp @@ -0,0 +1,53 @@ +/*풀이1 재귀만 이용*/ +//#include +//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 +#include +using namespace std; + +vector> 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>(k + 1, vector(n + 1, -1)); //케이스별 DP 테이블 초기화 + cout << calc(k, n) << "\n"; + } + return 0; +} diff --git a/oesnuj/README.md b/oesnuj/README.md index bc15eeb..7d0b194 100644 --- a/oesnuj/README.md +++ b/oesnuj/README.md @@ -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) | --- From 20e59d32a5c69edae3fc99f963bb3dd63d8164af Mon Sep 17 00:00:00 2001 From: Junseo Kim Date: Tue, 6 Aug 2024 05:00:36 +0900 Subject: [PATCH 2/3] =?UTF-8?q?2024-08-05=20=EB=82=98=EB=8A=94=EC=95=BC=20?= =?UTF-8?q?=ED=8F=AC=EC=BC=93=EB=AA=AC=20=EB=A7=88=EC=8A=A4=ED=84=B0=20?= =?UTF-8?q?=EC=9D=B4=EB=8B=A4=EC=86=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oesnuj/README.md | 1 + "oesnuj/\355\225\264\354\213\234/1620.js" | 27 +++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 "oesnuj/\355\225\264\354\213\234/1620.js" diff --git a/oesnuj/README.md b/oesnuj/README.md index 7d0b194..7449522 100644 --- a/oesnuj/README.md +++ b/oesnuj/README.md @@ -15,4 +15,5 @@ | 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) | +| 14차시 | 2024.08.05 | 해시 | [ 나는야 포켓몬 마스터 이다솜 ](https://www.acmicpc.net/problem/1620) | [#46](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/46) | --- diff --git "a/oesnuj/\355\225\264\354\213\234/1620.js" "b/oesnuj/\355\225\264\354\213\234/1620.js" new file mode 100644 index 0000000..d78b8f5 --- /dev/null +++ "b/oesnuj/\355\225\264\354\213\234/1620.js" @@ -0,0 +1,27 @@ +const fs = require('fs'); +const filepath = process.platform === 'linux' ? '/dev/stdin' : './input.txt'; +const input = fs.readFileSync(filepath).toString().trim().split('\n'); + +const N = +input[0].split(' ')[0]; +const pokemonList = input.slice(1, 1 + N); +const testList = input.slice(1 + N); + +// 이름을 키로 하고 번호를 값으로 하는 단일 Map 객체 생성 +const pokemonMap = new Map(); +pokemonList.forEach((pokemon, index) => { + const number = index + 1; + pokemonMap.set(pokemon, number); +}); + +let result = ''; +testList.forEach(test => { + const num = Number(test); + if (!isNaN(num)) { + // 테스트 값이 번호인 경우 + result += pokemonList[num - 1] + '\n'; // 번호에 해당하는 Pokémon 이름 추가 + } else { + // 테스트 값이 이름인 경우 + result += pokemonMap.get(test) + '\n'; // 이름에 해당하는 Pokémon 번호 추가 + } +}); +console.log(result); \ No newline at end of file From ca505a7f5a034b46e07d5a8841dad6d4b52e967a Mon Sep 17 00:00:00 2001 From: Junseo Kim Date: Tue, 6 Aug 2024 05:02:09 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=EB=B8=8C=EB=9E=9C=EC=B9=98=20=EA=B3=A0?= =?UTF-8?q?=EC=B9=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oesnuj/README.md | 1 - "oesnuj/\355\225\264\354\213\234/1620.js" | 27 ----------------------- 2 files changed, 28 deletions(-) delete mode 100644 "oesnuj/\355\225\264\354\213\234/1620.js" diff --git a/oesnuj/README.md b/oesnuj/README.md index 7449522..7d0b194 100644 --- a/oesnuj/README.md +++ b/oesnuj/README.md @@ -15,5 +15,4 @@ | 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) | -| 14차시 | 2024.08.05 | 해시 | [ 나는야 포켓몬 마스터 이다솜 ](https://www.acmicpc.net/problem/1620) | [#46](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/46) | --- diff --git "a/oesnuj/\355\225\264\354\213\234/1620.js" "b/oesnuj/\355\225\264\354\213\234/1620.js" deleted file mode 100644 index d78b8f5..0000000 --- "a/oesnuj/\355\225\264\354\213\234/1620.js" +++ /dev/null @@ -1,27 +0,0 @@ -const fs = require('fs'); -const filepath = process.platform === 'linux' ? '/dev/stdin' : './input.txt'; -const input = fs.readFileSync(filepath).toString().trim().split('\n'); - -const N = +input[0].split(' ')[0]; -const pokemonList = input.slice(1, 1 + N); -const testList = input.slice(1 + N); - -// 이름을 키로 하고 번호를 값으로 하는 단일 Map 객체 생성 -const pokemonMap = new Map(); -pokemonList.forEach((pokemon, index) => { - const number = index + 1; - pokemonMap.set(pokemon, number); -}); - -let result = ''; -testList.forEach(test => { - const num = Number(test); - if (!isNaN(num)) { - // 테스트 값이 번호인 경우 - result += pokemonList[num - 1] + '\n'; // 번호에 해당하는 Pokémon 이름 추가 - } else { - // 테스트 값이 이름인 경우 - result += pokemonMap.get(test) + '\n'; // 이름에 해당하는 Pokémon 번호 추가 - } -}); -console.log(result); \ No newline at end of file