UV 12222 (dp), uva12222dp
There is A one-way street. There will be cars on both ends of A and B to pass through. Now n vehicles are provided. The departure location, departure time, and time of each vehicle passing through this road, ask the minimum time point for the last car to leave the road. Note: The opposite car cannot be on the road at the same time, but there is a 10-second gap between the vehicles in the same direction, that is, any point on the road can only pass by one car within 10 seconds.
Question: considering that there is a car on both sides of the one-way street, you can start with the status of the two sides of the car, f [I] [j] [k] indicates the minimum time for A car to enter from the k end after the first car of Terminal A and the first car of Terminal B has left. Then, you can enumerate the shortest time used to continuously update the-end vehicle from the I + 1 (which takes A shorter time, and the shortest time used to continuously pass the update from the B-end of the j + 1 vehicle,
# Include <stdio. h> # include <string. h ># include <algorithm> using namespace std; const int N = 205; const int INF = 0x3f3f3f3f; struct Car {int t, d;} A [N], B [N]; int n, f [N] [N] [2], cnt1, cnt2; char str [5]; int main () {int cas; scanf ("% d", & cas); while (cas --) {cnt1 = cnt2 = 1; scanf ("% d", & n ); for (int I = 1; I <= n; I ++) {scanf ("% s", str); if (str [0] = 'A ') {scanf ("% d", & A [cnt1]. t, & A [cnt1]. d); cnt1 ++;} else {scanf ("% d", & B [cnt2]. t, & B [cnt2]. d); cnt2 ++ ;}} memset (f, INF, sizeof (f )); f [0] [0] [0] = f [0] [0] [1] = 0; for (int I = 0; I <cnt1; I ++) {for (int j = 0; j <cnt2; j ++) {int s = f [I] [j] [0], e = 0; // A has A car in the for (int k = I + 1; k <cnt1; k ++) {s = max (s, A [k]. t); e = max (e, s + A [k]. d); f [k] [j] [1] = min (f [k] [j] [1], e ); // At the same time, the minimum time point s + = 10 for a car to enter from the B end; // The 10-second interval e + = 10 for continuous entry from the same end; // right shift between start and end time} s = f [I] [j] [1], e = 0; // a car enters for (int k = j + 1; k <cnt2; k ++) {s = max (s, B [k]. t); e = max (e, s + B [k]. d); f [I] [k] [0] = min (f [I] [k] [0], e); s + = 10; e + = 10 ;}} printf ("% d \ n", min (f [cnt1-1] [cnt2-1] [0], f [cnt1-1] [cnt2-1] [1]);} return 0 ;}
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.