From 4c8bdc19a98d47edbfd72d909cd14d92510f92ca Mon Sep 17 00:00:00 2001 From: SeongWooHong Date: Wed, 7 Feb 2024 00:00:47 +0900 Subject: [PATCH 1/3] 2024-02-06 --- Redish03/Backtracking/15663.cpp | 65 +++++++++++++++++++++++++++++++++ Redish03/README.md | 3 +- 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 Redish03/Backtracking/15663.cpp diff --git a/Redish03/Backtracking/15663.cpp b/Redish03/Backtracking/15663.cpp new file mode 100644 index 0000000..4dc092e --- /dev/null +++ b/Redish03/Backtracking/15663.cpp @@ -0,0 +1,65 @@ +#include +#include + +using namespace std; + +int arr[10]; +int N, M; +int current[8]; +int previ[8]; +bool used[8]; + +bool check_duplicate() +{ + for (int i = 0; i < M; i++) + { + if (current[i] != previ[i]) + { + return false; + } + } + return true; +} + +void find_arr(int count) +{ + if (count == M) + { + if (check_duplicate()) + { + return; + } + for (int i = 0; i < M; i++) + { + previ[i] = current[i]; + cout << current[i] << " "; + } + cout << '\n'; + + return; + } + + int tmp = 0; + for (int i = 0; i < N; i++) + { + if (used[i] || tmp == arr[i]) + continue; + current[count] = arr[i]; + tmp = arr[i]; + used[i] = true; + find_arr(count + 1); + used[i] = false; + } +} + +int main() +{ + cin >> N >> M; + for (int i = 0; i < N; i++) + { + cin >> arr[i]; + } + sort(arr, arr + N); + + find_arr(0); +} \ No newline at end of file diff --git a/Redish03/README.md b/Redish03/README.md index 9bca444..9017612 100644 --- a/Redish03/README.md +++ b/Redish03/README.md @@ -13,6 +13,7 @@ | 9차시 | 2024.01.25 | Back tracking | [N과 M(7)](https://www.acmicpc.net/problem/15656) | [#9](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/35) | | 10차시 | 2024.01.28 | DP | [내려가기](https://www.acmicpc.net/problem/2096) | [#10](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/41) | | 11차시 | 2024.01.31 | Greedy | [삼각형 만들기](https://www.acmicpc.net/problem/1448) | [#11](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/44) | -| 12차시 | 2024.02.03 | DP | [구간 합 구하기 5](https://www.acmicpc.net/problem/11660) | [#12](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/44) | +| 12차시 | 2024.02.03 | DP | [구간 합 구하기 5](https://www.acmicpc.net/problem/11660) | [#12](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/47) | +| 13차시 | 2024.02.06 | Back tracking | [N과 M(9)](https://www.acmicpc.net/problem/15663) | [#13](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/47) | --- From 4d6f0bcdd848505e2e768854d234fbb1dc60a42e Mon Sep 17 00:00:00 2001 From: SeongWooHong Date: Tue, 13 Feb 2024 00:45:32 +0900 Subject: [PATCH 2/3] 2024-02-12 --- Redish03/DP/12865.cpp | 0 Redish03/README.md | 3 ++- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 Redish03/DP/12865.cpp diff --git a/Redish03/DP/12865.cpp b/Redish03/DP/12865.cpp new file mode 100644 index 0000000..e69de29 diff --git a/Redish03/README.md b/Redish03/README.md index 9017612..a70a1e0 100644 --- a/Redish03/README.md +++ b/Redish03/README.md @@ -14,6 +14,7 @@ | 10차시 | 2024.01.28 | DP | [내려가기](https://www.acmicpc.net/problem/2096) | [#10](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/41) | | 11차시 | 2024.01.31 | Greedy | [삼각형 만들기](https://www.acmicpc.net/problem/1448) | [#11](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/44) | | 12차시 | 2024.02.03 | DP | [구간 합 구하기 5](https://www.acmicpc.net/problem/11660) | [#12](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/47) | -| 13차시 | 2024.02.06 | Back tracking | [N과 M(9)](https://www.acmicpc.net/problem/15663) | [#13](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/47) | +| 13차시 | 2024.02.06 | Back tracking | [N과 M(9)](https://www.acmicpc.net/problem/15663) | [#13](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/52) | +| 14차시 | 2024.02.12 | KnapSack(DP) | [평범한 배낭](https://www.acmicpc.net/problem/12865) | [#14](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/47) | --- From 299e904b3d9a14371f405f669662ed8bec96894e Mon Sep 17 00:00:00 2001 From: SeongWooHong Date: Tue, 13 Feb 2024 00:46:21 +0900 Subject: [PATCH 3/3] 2024-02-12 --- Redish03/DP/12865.cpp | 39 +++++++++++++++++++++++++++++++++++++++ Redish03/README.md | 2 +- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/Redish03/DP/12865.cpp b/Redish03/DP/12865.cpp index e69de29..df871ac 100644 --- a/Redish03/DP/12865.cpp +++ b/Redish03/DP/12865.cpp @@ -0,0 +1,39 @@ +#include + +using namespace std; + +int N, K; +int dp[101][100001]; +int weight[101]; +int value[101]; + +int main() +{ + ios_base::sync_with_stdio(false); + cin.tie(0); + cout.tie(0); + + cin >> N >> K; + + for (int i = 1; i <= N; i++) + { + cin >> weight[i] >> value[i]; + } + + for (int i = 1; i <= N; i++) + { + for (int j = 1; j <= K; j++) + { + if (j >= weight[i]) + { + dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - weight[i]] + value[i]); + } + else + { + dp[i][j] = dp[i - 1][j]; + } + } + } + + cout << dp[N][K]; +} \ No newline at end of file diff --git a/Redish03/README.md b/Redish03/README.md index a70a1e0..6490b3e 100644 --- a/Redish03/README.md +++ b/Redish03/README.md @@ -15,6 +15,6 @@ | 11차시 | 2024.01.31 | Greedy | [삼각형 만들기](https://www.acmicpc.net/problem/1448) | [#11](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/44) | | 12차시 | 2024.02.03 | DP | [구간 합 구하기 5](https://www.acmicpc.net/problem/11660) | [#12](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/47) | | 13차시 | 2024.02.06 | Back tracking | [N과 M(9)](https://www.acmicpc.net/problem/15663) | [#13](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/52) | -| 14차시 | 2024.02.12 | KnapSack(DP) | [평범한 배낭](https://www.acmicpc.net/problem/12865) | [#14](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/47) | +| 14차시 | 2024.02.12 | KnapSack(DP) | [평범한 배낭](https://www.acmicpc.net/problem/12865) | [#14](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/55) | ---