Topic:
Sample input:
9
8 4 2 5 3 9 1 6 7
Sample output:
4
Ideas:
To get the fewest scheduling sequences, find the minimum number of descent sequences. Take the above example: there are four descending sequences
8 4 2 1
5 3
9 6
7
So only four dispatch queues are required.
Also according to the theorem: the minimum number of descent sequences equals the length of the longest ascending subsequence. (This theorem proves not understand, direct Meng, dish is original sin ah!!) The rest is a bare longest ascending subsequence problem.
Code:
#include <bits/stdc++.h>#defineINF 0x3f3f3f3fusing namespaceStd;typedefLong Longll;Const intMAXN = 1e5+Ten;intA[MAXN],DP[MAXN];intMain () {intN; scanf ("%d",&N); for(inti =0; i<n; i++) {scanf ("%d",&A[i]); Dp[i]=inf; } intMmax =-1; for(inti =0; i<n; i++) { intK = Lower_bound (Dp,dp+n,a[i])-DP; DP[K]=A[i]; Mmax= Max (Mmax, K +1); } printf ("%d\n", Mmax); return 0;}
View Code
7-2 Train scheduling (25 points)