Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

14-redish03 #55

Merged
merged 3 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions Redish03/Backtracking/15663.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include <iostream>
#include <algorithm>

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);
}
39 changes: 39 additions & 0 deletions Redish03/DP/12865.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include <iostream>

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];
}
4 changes: 3 additions & 1 deletion Redish03/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
| 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/52) |
| 14์ฐจ์‹œ | 2024.02.12 | KnapSack(DP) | [ํ‰๋ฒ”ํ•œ ๋ฐฐ๋‚ญ](https://www.acmicpc.net/problem/12865) | [#14](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/55) |

---