SSL-OI Summer Camp Miscellaneous Problem LOJ#6089 Little Y's Backpack Counting Problem Square Root Decomposition

LOJ 6089 This problem is a miscellaneous problem from the first night of the training camp. Due to my nature of loving to procrastinate, I only came to write the solution in the second week of the training camp. Prerequisite knowledge [Multiple Knapsack]https://www.luogu.com.cn/problem/P1776: Optimized with monotonic queue, achieving ONMONM complexity. [Integer Partition]https://www.luogu.com.cn/problem/P1025: The number of ways to form nn integers from kk integers (with/without repetition), ONKONK complexity DP. Problem statement Backpack size is nn, item

LOJ #6089

This problem is a miscellaneous problem from the first night of the training camp. Due to my nature of loving to procrastinate, I only came to write the solution in the second week of the training camp.

Prerequisite Knowledge

Multiple Knapsack: Optimized with monotonic queue, achieving O(NM)O(NM) complexity.

Integer Partition: The number of ways to form nn integers from kk integers (with/without repetition), O(NK)O(NK) complexity DP.

Problem Statement

Backpack size is nn, number of items is nn, the weight of the ii-th item is ii, and the quantity is ii.

Question: What is the number of ways to fill the backpack?

Correct Solution

For items greater than N\sqrt{N}, it is equivalent to having no quantity limit. We use integer partition (with repetition) to find the answer.

For items less than N\sqrt{N}, we use multiple knapsack to find the answer. Since the number of items is N\sqrt{N} and the backpack size is NN, the complexity is O(NN)O(N\sqrt{N}).

Comments

0

No comments yet.