Conversion backpack HDU 4381 Grid

Source: Internet
Author: User

Channel:Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 4381

Question:N blocks, numbers from 1 to n, and m operations. At first, N blocks are black. There are two types of operations (you can ignore some operations and you cannot perform this operation if there are not enough black blocks in the interval (Black Blocks are used for whitelist ):

1. Ai Xi: Select Xi blocks from [1, Ai] to whitelist these blocks.

2. Ai Xi: Select Xi blocks from [ai, N] to whitelist these blocks.

Ideas:The difficulty of this question lies in the correct processing of two kinds of operations. Assume that there is only one operation, then if this operation is 1, the operation will be sorted by a from small to large, try to apply to the leftmost image every time. If it is 2, it applies to the rightmost image.

First consider the first question:

We separate all operations by category. Assume that all 1 operations can be painted from 1 to a lattice as much as possible, and all 2 operations can be painted from B lattice to N as much as possible, suppose a <B, then the answer is obviously a + N-B + 1. If a> = B, then if 1 is applied from 1 to X, then 2 will apply from N to the left as far as possible until X. The sum of the two sides is the answer.

It is not difficult to think of a DP. L [I] [J] indicates the minimum operand from 1 to J using the first I type 1 operation, transfer L [I] [J] = min (L [I] [J], L [I-1] [J-ope [I]. x] + 1) (OPE [I]. x <= j <= ope [I]. a). Similarly, we can obtain the R [I] [J], which indicates the minimum operand required to apply the 2 operation from J to n. DP complexity O (N * m ). (This backpack can also be compressed into one dimension, and the L and R behind it are in a one-dimensional state)

Then we will flip the enumeration coloring to the largest number. For example, if it is K, this number must be contributed by one operation, and contributed by one operation (or one contribution may be all, and the other is 0 ), then, if the enumeration 1 operation is applied to I, the operation 2 must be applied to N-(k-I) + 1. If l [I] and R [N-(k-I) + 1] If there are values, it indicates that the maximum number is reachable, which is the answer to the first question. Enumeration complexity O (N * n ).

Another question:

Now we know the maximum number. This number is contributed by operation 1 and operation 2, so we can still apply enumeration operation 1 to I, then operation 2 is coated with N-(ANS-I) + 1. If l [I] and R [N-(k-I) + 1] have values, the sum can be used to update the answer to the second question. The answer to the second question is the minimum value of the operands required for all valid solutions. Enumeration complexity O (N * n)

Code:Https://github.com/Mithril0rd/Rojo/blob/master/hdu4381.cpp

Tag: conversion of a backpack

Conversion backpack HDU 4381 Grid

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.