Educational Codeforces Round 73

Posted liuwenhan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Educational Codeforces Round 73相关的知识,希望对你有一定的参考价值。

1334 (-2), pupil
Rank: 2668

(虽然比上次好,但是摆脱不了掉分的命运。。。)

D. Make The Fence Great Again

http://codeforces.com/contest/1221/problem/D

分析:对每个高度来说,最多升高两次,因此可以对这个进行dp(一开始读错题了,没有看到是相邻不能同高,一开始以为所有都不能同高)

代码:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int maxn = 1e6;
 4 typedef long long ll;
 5 const ll inf = 0x3f3f3f3f3f3f3f3f;
 6 int n;
 7 int h[maxn], w[maxn];
 8 ll dp[maxn][3];
 9 
10 int main()
11 
12     int T; cin >> T;
13     while (T--)
14     
15         int n; cin >> n;
16         for (int i = 1; i <= n; i++)
17             scanf("%d%d", h + i, w + i);
18         for (int i = 1; i <= n; i++)
19             dp[i][0] = dp[i][1] = dp[i][2] = inf;
20         dp[1][0] = 0, dp[1][1] = w[1], dp[1][2] = 2 * w[1];
21         for (int i = 2; i <= n; i++)
22         
23             for (int j = 0; j <= 2; j++)
24                 for (int k = 0; k <= 2; k++)
25                     if (h[i - 1] + j != h[i] + k)
26                         dp[i][k] = min(dp[i][k], w[i] * k + dp[i - 1][j]);
27         
28         cout << min(dp[n][0], min(dp[n][1], dp[n][2])) << endl;
29     
30 

 

以上是关于Educational Codeforces Round 73的主要内容,如果未能解决你的问题,请参考以下文章

Educational Codeforces Round 7 A

Educational Codeforces Round 7

Educational Codeforces Round 90

Educational Codeforces Round 33

Codeforces Educational Codeforces Round 54 题解

Educational Codeforces Round 27