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

17-Redish03 #73

Merged
merged 4 commits into from
Mar 6, 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
3 changes: 2 additions & 1 deletion Redish03/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"files.associations": {
"iostream": "cpp",
"algorithm": "cpp"
"algorithm": "cpp",
"vector": "cpp"
}
}
47 changes: 47 additions & 0 deletions Redish03/DP/10844.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <iostream>
#define DVD 1000000000

using namespace std;

int N;

long long number_cnt = 0;
long long dp[101][10] = {
0,
};
Comment on lines +9 to +11

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ „μ—­ λ³€μˆ˜λ‘œ 배열을 μƒμ„±ν•˜λ©΄, μžλ™μ μœΌλ‘œ λ‚΄λΆ€ μ›μ†Œλ“€μ΄ 0κ°’μœΌλ‘œ μ΄ˆκΈ°ν™”λ©λ‹ˆλ‹€. λ”°λ‘œ 0으둜 μ΄ˆκΈ°ν™” λͺ…μ‹œλ₯Ό ν•  ν•„μš”λŠ” μ—†λ‹΅λ‹ˆλ‹Ή.


int main()
{
cin >> N;
for (int i = 1; i < 10; i++)
{
dp[1][i] = 1;
}
for (int i = 2; i <= N; i++)
{
for (int j = 0; j <= 9; j++)
{
if (j == 0)
{
dp[i][j] = dp[i - 1][1];
}
else if (j == 9)
{
dp[i][j] = dp[i - 1][8];
}
else
{
dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j + 1]);
}
dp[i][j] %= DVD;
}
}

for (int i = 0; i < 10; i++)
{
number_cnt += dp[N][i];
number_cnt %= DVD;
}

cout << number_cnt;
}
39 changes: 39 additions & 0 deletions Redish03/DP/9461.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include <iostream>

using namespace std;

long long dp[101] = {
0,
};

long long rec(int N)
{
if (dp[N] != 0)
{
return dp[N];
}
if (N == 1 || N == 2 || N == 3)
{
dp[N] = 1;
return 1;
}

dp[N] = rec(N - 2) + rec(N - 3);
return dp[N];
}
Comment on lines +9 to +23
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

νƒ‘λ‹€μš΄ ν˜•μ‹μ˜ DPλ„€μš”! μž¬κ·€λ₯Ό μ΄μš©ν•˜λŠ” 만큼 κ°„κ²°ν•˜κ³  짧은 μ½”λ“œμ˜ μž₯점, 느린 단점이 있죠. λ§Œμ•½ λͺ‡ ꡬ간 κ±΄λ„ˆλ›Έ 수 μžˆλ‹€λ©΄ 더 κΈˆμƒμ²¨ν™”κ² μ£ . (κ·Έλž˜λ„ 보톡 λ‹€ μ±„μš°λŠ” 바텀업이 더 λΉ λ₯΄κΈ΄ ν•©λ‹ˆλ‹€.)

이번 점화식은, 잘 생각해보면 κ²°κ΅­ 거의 λͺ¨λ“  칸이 μ±„μ›Œμ§„λ‹€λŠ” 사싀을 μ•Œ 수 μžˆμŠ΅λ‹ˆλ‹€. μœ μΌν•˜κ²Œ κ±΄λ„ˆλ›°λŠ” 칸은 N-1이죠. κ·Έλž˜μ„œ 별 영ν–₯이 μ—†...


int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

int T, N;
cin >> T;

for (int i = 0; i < T; i++)
{
cin >> N;
cout << rec(N) << '\n';
}
}
4 changes: 3 additions & 1 deletion Redish03/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
| 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) |
| 15μ°¨μ‹œ | 2024.02.15 | DFS | [트리의 지름](https://www.acmicpc.net/problem/1167) | [#14](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/55) |
| 15μ°¨μ‹œ | 2024.02.15 | DFS | [트리의 지름](https://www.acmicpc.net/problem/1167) | [#15](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/55) |
| 16μ°¨μ‹œ | 2024.02.27 | DP | [μ‰¬μš΄ 계단 수](https://www.acmicpc.net/problem/10844) | [#16](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/68) |
| 17μ°¨μ‹œ | 2024.03.01 | DP | [νŒŒλ„λ°˜ μˆ˜μ—΄](https://www.acmicpc.net/problem/9461) | [#17](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/68) |

---