์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
- ์ฐ์ ์์ ํ
- ์ด๋ถ ํ์
- ๋ฐ์ดํฌ์คํธ๋ผ
- ์๋ฎฌ๋ ์ด์
- Reversing
- ๋งต
- OS
- ๊ทธ๋ฆฌ๋
- web
- ์ฌ๊ท
- GCP
- c++
- ๊ตฌํ
- ๋ถํ ์ ๋ณต
- Spring
- ์์ ์ ๋ ฌ
- ๋ฌธ์์ด
- DP
- ์ต๋จ ๊ฒฝ๋ก
- ๋์ ํฉ
- dynamic debugging
- CVE
- dfs
- ์คํ
- java
- BFS
- error
- thymeleaf
- ๋ฐฑํธ๋ํน
- JPA
- Today
- Total
hades
[Baekjoon] 9465๋ฒ: ์คํฐ์ปค ๋ณธ๋ฌธ
๐ฅ ๋ฌธ์
https://www.acmicpc.net/problem/9465
๐ ์ค๊ณ
์ฒ์์ ์ ์ด์์ ์ด๋ค ํ์ ์ฌ์ฉํ๋์ง์ ๋ฐ๋ผ ํ์ ์ถ๊ฐํ๋ ๋ฐฉ์์ ์ฌ์ฉํ๋ ค๊ณ ์๊ฐํด๋ณด์๋๋ฐ, 2^100000์ผ๋ก ์๊ฐ ์ด๊ณผ๊ฐ ๋ฐ์ํ ๊ฒ์ผ๋ก ์๊ฐ๋์ด ์ ์ธํ์๋ค.
์ฝ๊ฒ ๋ค์ด๋๋ฏน ํ๋ก๊ทธ๋๋ฐ์ ์ด์ฉํ์ฌ ํด๊ฒฐํ ์ ์๋ค. ํ์ฌ ์ด์์ 0ํ์ ์ฌ์ฉํ ๊ฒ์ด๋ผ๋ฉด, ์ ์ด์์๋ 1ํ ๋๋ ์๋ฌด๊ฒ๋ ์ฌ์ฉํ์ง ์์์ ๋์ ๊ฐ ์ค ์ต๋๊ฐ์ ๋ํด์ผ ํ๋ค. ์๋ฌด ๊ฒ๋ ์ฌ์ฉํ์ง ์์์ ๋๋ ์ธ๋ฑ์ค 2์ ์ ์ฅํ์๋ค. ํ์ฌ ์ด์์ 1ํ์ ์ฌ์ฉํ ๊ฒ์ด๋ผ๋ฉด, ์ ์ด์์๋ 0ํ ๋๋ ์๋ฌด๊ฒ๋ ์ฌ์ฉํ์ง ์์์ ๋์ ๊ฐ ์ค ์ต๋๊ฐ์ ๋ํด์ผ ํ๋ค ํ์ฌ ์ด์์ ์๋ฌด๊ฒ๋ ์ฌ์ฉํ์ง ์์ ๊ฒ์ด๋ผ๋ฉด, ์ ์ด์์ 0ํ์ ์ฌ์ฉ์ ์ฌ์ฉํ์ ๋์ 1ํ์ ์ฌ์ฉํ์ ๋ ์ค ํฐ ๊ฐ์ ์ ์ฅํ๋ฉด ๋๋ค.
๐ ํ์ด
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int t, n;
vector<vector<int>> stickers(2, vector<int>(100000));
vector<vector<int>> dp(100000, vector<int>(3));
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> t;
for (int k = 0; k < t; k++) {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> stickers[0][i];
}
for (int i = 0; i < n; i++) {
cin >> stickers[1][i];
}
dp[0][0] = stickers[0][0];
dp[0][1] = stickers[1][0];
for (int i = 1; i < n; i++) {
dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + stickers[0][i];
dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + stickers[1][i];
dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]);
}
int result = 0;
for (int i = 0; i < 3; i++) {
result = max(result, dp[n - 1][i]);
}
cout << result << "\n";
}
return 0;
}
'๐ PS > Algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Baekjoon] 2638๋ฒ: ์น์ฆ (0) | 2024.08.13 |
---|---|
15654๋ฒ: N๊ณผ M (5) (0) | 2024.08.12 |
[Baekjoon] 2096๋ฒ: ๋ด๋ ค๊ฐ๊ธฐ (0) | 2024.08.10 |
[Baekjoon] 1987๋ฒ: ์ํ๋ฒณ (0) | 2024.08.09 |
[Baekjoon] 1918๋ฒ: ํ์ ํ๊ธฐ์ (0) | 2024.08.08 |