Codeforces 608C: (DP)

Source: Internet
Author: User

From the lighthouse to the left, light one, and all the lighthouses in the left Di range are destroyed. You can now press a lighthouse at the far right, with any range of attacks, and ask at least a few lighthouses to leave at the end.

With the DP blind. Look at the code specifically.

#include"Cstdio"#include"Queue"#include"Cmath"#include"Stack"#include"iostream"#include"algorithm"#include"CString"#include"Queue"#include"Vector"#definell Long Longusing namespacestd;Const intMAXN =1e6;Const intMaxe =200500;Const intINF =0x3f3f3f;structnode{intb;} X[MAXN];intSUM[MAXN];intdp[maxn*Ten];BOOLCMP (node X,node y) {returnx.a<y.a;}intMain () {intN;SCANF ("%d",&N); intmaxv=-1;  for(intI=0; i<n;i++) {scanf ("%d%d",&x[i].a,&x[i].b); MAXV=Max (MAXV,X[I].A); }    if(n==1) {printf ("0\n"); return 0; } sort (X,x+n,cmp); dp[x[0].a]=1;  for(inti=x[0].a+1, j=1; i<=maxv;i++){        if(i>=x[j].a) {            intt=x[j].a-x[j].b-1; if(t>=0) dp[i]=dp[t]+1; Elsedp[i]=1; J++; }        Elsedp[i]=dp[i-1]; }    intans=INF;  for(inti=x[0].a;i<=maxv;i++) Ans=min (ans,n-Dp[i]); //cout<<i<< ' \ t ' <<dp[i]<<endl;printf"%d\n", ans); return 0;}
View Code

Codeforces 608C: (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.