7-2 Train scheduling (25 points)

Source: Internet
Author: User

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)

Contact Us

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.