Preparing a knapsack problem
Time limit1sMemory limit32 MB
Read t up to 1e18 and print k = 300 with sixty 1s plus extra elements chosen by greedy binomial decomposition so exactly t subsets sum to 300.
- Level
Easy3 of 10
- Topics
- Combinatorics, Implementation
- Solved
- No attempts yet
Problem
Making test data is a large part of setting a problem. There is no fixed recipe for it. For each problem you list the wrong answers that solvers are likely to write, then prepare data that catches them.
Consider the following problem.
A multiset is given. How many subsets of have element sum exactly ? Two elements with the same value but different positions count as different.
The constraints are and , and every element of is a natural number no greater than .
One wrong answer for it prints on data whose true answer is . To catch that answer you need a program that takes a natural number and produces a multiset and a natural number whose answer is exactly . Write that program.
Many data sets satisfy the condition, so only the one built by the method given in the output section is accepted.
Input
The first line contains a natural number . ()
Output
On the first line print and , separated by a space. On the second line print in nondecreasing order, separated by spaces. , and must satisfy the constraints above.
Build the data by this method only.
- Set .
- Put 60 elements of value 1 into .
- Set . While , take the largest integer with and , put one element of value into , then subtract from .
- is the total number of elements put into .
Each element added in step 3 lies in exactly subsets of sum 300, and every subset of sum 300 contains exactly one element added in step 3. The answer for this data is therefore exactly . For the value of never exceeds 242.