Codeforces 269B B. Greenhouse Effect (DP)

Source: Internet
Author: User

Topic Links:

Codeforces

Main topic:

Give a real axis, which is scattered n points, they are m species, ask at least how many steps can be divided into the number of points on the axis of the 1~m order of the kind of M block.

Topic Analysis:
  • First we can know that there must be a strategy to place a point once to where it should be placed.
  • So for the plants we want to move, we have to move at most for each plant, defining state dp[i] to represent the first I plant, to ensure that the maximum number of plants to keep in ascending order.
  • The transfer equation is obvious, d P[I]=max{d P[J]}+1,s[I]>= s[J]
  • We add a plant of type m+1 at the end of the sequence so that the last plant we retain is dp[n], and then the moving plant only needs to be moved once, so N-dp[n] is the final answer.
AC Code:
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#define MAX 5007using namespace STD;intN,m,s[max],dp[max];DoubleXintMain () { while( ~scanf("%d%d", &n, &m)) { for(inti =1; I <= N; i++)scanf("%d%lf", &s[i], &x); S[++n] = m+1; for(inti =1; I <= N; i++) {Dp[i] =0; for(intj =1; J < I; J + +)if(S[i] >= s[j]) dp[i] = max (Dp[i], dp[j]);        dp[i]++; }printf("%d\n", N-dp[n]); }}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Codeforces 269B B. Greenhouse Effect (DP)

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.