Light OJ 1084 Linear DP

Source: Internet
Author: User

1#include <iostream>2#include <algorithm>3#include <cstring>4#include <cstdio>5#include <queue>6 #definell Long Long7 8 using namespacestd;9 Const intN = 1e5+ +;Ten  One intA[n],dp[n]; A  - voidSolve () - { the     intn,k; -scanf"%d%d",&n,&k); -      for(inti =0; I < n; i++) -     { +scanf"%d",&a[i]); -     } +Sort (a,a+n); AMemset (DP,0,sizeof(DP)); at      for(inti = n1; I >=0; i--) -     { -Dp[i] =0x3f3f3f; -         intj = Upper_bound (a,a+n,a[i]+2*K)-A; -         if(J-i >=3) Dp[i] = min (dp[j]+1, Dp[i]); -         if(J-i >=4) Dp[i] = min (dp[j-1]+1, Dp[i]); in         if(J-i >=5) Dp[i] = min (dp[j-2]+1, Dp[i]); -     } to     if(dp[0] ==0x3f3f3f) +printf"-1\n"); -     Else theprintf"%d\n", dp[0]); * } $ Panax Notoginseng intMainvoid) - { the     intt,cnt =0; +scanf"%d",&t); A  the      while(t--) +     { -printf"Case %d:",++CNT); $ solve (); $     } -     return 0; -}

Light OJ 1084 Linear 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.