Jzoj 3521. Road cover

Source: Internet
Author: User

Descriptionar a bumpy road into a highly different n-segment, and uses h[i] to denote paragraph i height. There are now a total of n soils available in tar, all of which can cover a given continuous K-section.

For the type I soil, its price is c[i], can make the interval [I,min (n,i+k-1)] The height of the road segment increased e[i].

Tar to set a soil-use plan so that after using a number of soils, the minimum height of the road is as high as possible, and the plan must meet the following two requirements:

(1) Each type of soil can only be used once.

(2) The cost of soil use must be less than or equal to M.

The maximum number of requests for this minimum height. The input first behaves as three positive integers as shown above: N,m,k.

Next n rows, each line of 3 positive integers as shown above h[i],e[i],c[i]. Output outputs have only one number, the maximum value for the height of the bottom part of the sample Input
4 20 1
1 3 5
1 7 3
4 6 9
3 5 13
Sample Output
3

Procedure (Transfer from JZOJ):

Two points + state compression:
Two-minute enumeration of the lowest height, next consider the legitimacy: Set F[I][J] represents the minimum monetary cost of completing the J state in the first I bit, so long as the presence of State X makes f[n][x]≤m. Then consider the transition of the State: note For a I only by its former K-bit, so that is f[i][j] is obtained by its former K-bit, so that J has only K-bits. The range of k is very small, so it does not time out; to make the minimum height of the enumeration valid, it is also sufficient to satisfy the height ≥l after the point decision is completed. Then we can make state transitions based on conditions:
f[i+1][state J]=minx (F[i+1][j>>1],f[i][j]); And to meet the minimum height of x//the bit after the f[i+1][selected state J]=minx (f[i+1][(j>>1) | ( 1<< (k-1))],f[i][j]+c[i+1]); Meet "min height" for x//This bit selection

1#include <cstdio>2#include <cstring>3#include <iostream>4 #defineN 1075 using namespacestd;6 intC[n], e[n], h[n], N, M, K;7 intf[n][1<< A], L, R;8 9 voidInit ()Ten { Onescanf"%d%d%d", &n, &m, &k); A      for(intI=1; i<=n;i++) -scanf"%d%d%d", &h[i], &e[i], &c[i]); - } the  - BOOLCheckintx) { -Memset (F,0x7f7f7f7f,sizeof(f)); -f[0][0] =0; +      for(inti =0; I < n; i++) -          for(intj =0; J < (1<< k); J + +) +             if(F[i][j]! =0x7f7f7f7f)  A             { at                 intHeigh =0;  -                  for(intL =1; L < K; l++) -                     if(J & (1<< l) Heigh + = e[i-k + L +1]; -                 if(Heigh + h[i +1] >=x) -F[i +1][j >>1] = min (f[i +1][j >>1], f[i][j]); -                 if(Heigh + h[i +1] + e[i +1] >=x) inF[i +1[J >>1) | (1<< (K-1)] = min (f[i +1[J >>1) | (1<< (K-1)], F[i][j] + c[i +1]); -             } to      for(inti =0; I < (1<< k); i++) +         if(F[n][i] <= m)return 1; -     return 0;  the } *  $ intMain ()Panax Notoginseng { -Freopen ("cover.in","R", stdin); theFreopen ("Cover.out","W", stdout); + Init (); AL =0, r =1e8; the      while(L <R) +     { -         intMid = (L + R +1) /2; $         if(Check (mid)) L =mid; $         ElseR = Mid-1; -     } -printf"%d", L); the}
View Code

Jzoj 3521. Road cover

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.