51Nod Limited Backpack Counting problem report

Source: Internet
Author: User

First of all, this problem can theoretically be done by O (Nlogn), because there is a formula that can be accelerated by polynomial multiplication on oeis.

But because the modulus is not very magnetic, so it makes nlogn difficult to write

Here's an O (N*SQRT (n)) approach

First, it's easy to see that when the size of an item is >SQRT (n), the limit of the number of items is a dummy.

This means that the size of the item >sqrt (n) is actually a full backpack

And for a complete backpack, there is another approach (refer to the division of NOIP2001 number)

Since we know that if we only use >SQRT (n) items, we use up to sqrt (n) items

You may wish to set f[i][j] to show that I have used the items of I >sqrt (n) to spell out the scheme of J

We classify the discussion:

1. At least one of these I items is sqrt (n) +1

2, this I items are >sqrt (n) +1

can easily get a recursive f[i][j]=f[i][j-i]+f[i-1][j-sqrt (n)-1]

Since a maximum of sqrt (n) items are used, the number of States is N*SQRT (n), and the Transfer is O (1)

So the time complexity of this part is O (n*sqrt (n))

We then consider using only the <=SQRT (n) condition

This is obviously a simple multi-knapsack problem.

We all know that the time complexity of multiple knapsack problems is O (number of items * Backpack size)

So the complexity of Time is O (n*sqrt (n))

After merging two cases, Time complexity O (n*sqrt (n))

Well, the upper part of the problem is almost the NOIP2001 number division.

The lower part is a bare multi-pack.

So the overall is noip difficult, and I do 51Nod when I did not want to come out

So my level is below Noip

Certificate of Completion Qaq

By the way, the final merged formula is a convolution form

51Nod Limited Backpack Counting problem report

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.