Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Reputeless committed Feb 27, 2023
1 parent 27bd1ce commit 4b31c60
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
53 changes: 53 additions & 0 deletions 019.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# 019 - Pick Two(★6)

## 解答

```cpp
#include <iostream>
#include <algorithm>
#include <vector>

constexpr int INF = (1 << 29);

int AbsDiff(int a, int b)
{
return std::abs(a - b);
}

int main()
{
int N;
std::cin >> N;

std::vector<int> A(2 * N);
for (auto& a : A)
{
std::cin >> a;
}

// 区間 DP
std::vector<std::vector<int>> dp((2 * N), std::vector<int>(2 * N, INF));

for (int i = 0; i < (2 * N - 1); ++i)
{
dp[i][i + 1] = AbsDiff(A[i], A[i + 1]);
}

for (int tailLength = 3; tailLength <= (2 * N - 1); tailLength += 2)
{
for (int left = 0; left < (2 * N - tailLength); ++left)
{
int right = (left + tailLength);

for (int k = left; k < right; ++k)
{
dp[left][right] = std::min(dp[left][right], dp[left][k] + dp[k + 1][right]);
}

dp[left][right] = std::min(dp[left][right], dp[left + 1][right - 1] + AbsDiff(A[left], A[right]));
}
}

std::cout << dp[0][2 * N - 1] << '\n';
}
```
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ C++17 標準ライブラリの機能を優先して使い、競技プログラ

|問題|タイトル (解答コードへのリンク)|難易度|公式解説|キーワード (公式解説から引用)|
|:--:|--|:--:|:--:|--|
|[019](https://atcoder.jp/contests/typical90/tasks/typical90_s)|[Pick Two](./019.md)|★6|[👨‍🏫](https://raw.githubusercontent.com/E869120/kyopro_educational_90/main/editorial/019.jpg) / [📝](https://github.com/E869120/kyopro_educational_90/blob/main/sol/019.cpp)|列の操作は区間 DP|

### ★7

Expand Down

0 comments on commit 4b31c60

Please sign in to comment.