# UVA 12222 (DP)

Source: Internet
Author: User

Test instructions: There is a one-way street, A, b both ends will have a car to pass, now give n vehicles, each car departure location, departure time, through the road time, ask the last car left this road of the minimum time point. Note that the opposite car can not be on the road at the same time, and the same car to ensure there is a gap of 10 seconds, that is, any point on the road in 10 seconds can only pass a car.
Solving the puzzle: Considering that there are cars on both sides of one-way road, it is possible to start at both ends of the car, F[i][j][k] indicates that the end of a front I car, B-end before J car has left, at this time there is a car from the K-end into the minimum time point. Then the shortest time that can be used to update the vehicle continuously through an enumeration from the A-end of the i+1, which takes less time, and the car from the B-end of the j+1 is continuously updated by the shortest time,

``#include <stdio.h>#include <string.h>#include <algorithm>using namespace STD;Const intN =205;Const intINF =0x3f3f3f3f;structCar {intT, D;} A[n], b[n];intN, f[n][n][2], cnt1, Cnt2;Charstr[5];intMain () {intCAsscanf("%d", &cas); while(cas--) {cnt1 = Cnt2 =1;scanf("%d", &n); for(inti =1; I <= N; i++) {scanf('%s ', str);if(str[0] ==' A ') {scanf("%d%d", &a[cnt1].t, &AMP;A[CNT1].D);            cnt1++; }Else{scanf("%d%d", &b[cnt2].t, &AMP;B[CNT2].D);            cnt2++; }        }memset(F, INF,sizeof(f)); f[0][0][0] = f[0][0][1] =0; for(inti =0; i < cnt1; i++) { for(intj =0; J < Cnt2; J + +) {ints = f[i][j][0], E =0;There's a car on the//a side .                 for(intK = 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);//Update the minimum point at which the car enters from the B-terminal at this times + =Ten;//10-second continuous entry at the same endE + =Ten;//Start and end points at the same time move right} s = f[i][j][1], E =0;There's a car on the//b side .                 for(intK = 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 + =Ten; E + =Ten; }            }        }printf("%d\n", Min (F[cnt1-1][cnt2-1][0], F[cnt1-1][cnt2-1][1])); }return 0;}``

UVA 12222 (DP)

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.