The computer records the number of cars in front and back of each car at a certain time point (when multiple cars are side by side, only one car is in another car ), ask the minimum number of unreasonable data records.
Analysis: When we see n <= 1000, try to figure it out in DP.
Each input of a group of data A and B, if a + B> = N is certainly not good, plus itself will exceed n. Otherwise, the car must be in the range (a + 1, n-B). Therefore, the number of cars in the range (CNT [] [] records) ++, if the number of vehicles exceeds the range length, it will not be added. After completing the input data, DP:
Definition: DP [I]: the maximum number of vehicles in front of I is reasonable.
There is an equation: DP [I] = min (DP [J] + CNT [J + 1] [I]) (0 <= j <I)
That is, the maximum number of vehicles in the front I is equal to the maximum number of vehicles in the front J ~ I. The reasonable number of vehicles in this segment (CNT [] [] records the number of vehicles in a reasonable position)
Code:
# Include <iostream> # include <cstdio> # include <cstring> # include <cmath> # include <algorithm> using namespace STD; # define n 1507int DP [N]; int CNT [N] [N]; int main () {int cs = 1, n, I, j; int A, B; while (scanf ("% d ", & N )! = EOF & N) {memset (CNT, 0, sizeof (CNT); memset (DP, 0, sizeof (DP); for (I = 1; I <= N; I ++) {scanf ("% d", & A, & B); if (a + B> = N) continue; CNT [A + 1] [n-B] ++; If (CNT [A + 1] [n-B]> N-B-) // The Interval Length cannot exceed CNT [A + 1] [n-B] = N-B-a;} for (I = 1; I <= N; I ++) {for (j = 0; j <I; j ++) {DP [I] = max (DP [I], DP [J] + CNT [J + 1] [I]) ;}} printf ("case % d: % d \ n", CS ++, n-DP [N]);} return 0 ;}
View code