Educational Codeforces Round 73 (Rated for Div. 2)D(DP,思维)

HAVE_STRUCT_TIMESPEC #define
#include <bits / STDC ++ H.>
the using namespace STD;
Long Long A [300007], B [300007];
Long Long DP [300007] [. 5];
Long Long ANS;
int main () {
iOS :: sync_with_stdio (false); // sets of data input cin, cout easily timeout
cin.tie (NULL);
cout.tie (NULL);
int Q;
CIN >> Q;
the while (Q -) {
int n-;
ANS = 2e18;
CIN n->>;
DP [. 1] [0] = 0; // second dimension first dimension increased height, i.e. 0 is not increased, cost is 0
DP [. 1] [. 1] = B [. 1] ; // increase the cost of a height B [1]
DP [1] [2] = 2e18; // first point only need to add a height of up to connect with a [2] different, initialize it takes a maximum value
for (int i = 2; i < = n; ++ i) {// initialization
DP [I] [0] = 2e18;
DP [I] [. 1] = 2e18;
DP [I] [2] = 2e18;
}
for (int I =. 1; I <= n-; I ++)
CIN >> A [I] >> B [I];
for (int I = 2; I <= n-; I ++) {
for (int J = 0; J <. 3; J ++) {
for (int = 0 K; K <. 3; K ++) {
IF (k + a [i]! = a [i-1] + j) {// if the current a [i] and subsequent increase of the height of the last position k a [i-1] j increase after different height, It is intended to meet the problem
dp [i] [k] = min (dp [i-1] [j] + b [i] * k, dp [i] [k]); // update location k i increase the height of the desired minimum cost
}
}
}
}
for (int I = 0; I <. 3; I ++) {
ANS = min (DP [n-] [I], ANS);
}
COUT ANS << << "\ n-";
}
0 return;
}

Guess you like

Origin www.cnblogs.com/ldudxy/p/11566649.html