Problem 652
Profitable Schemes
Hard · 30 pts · Dynamic Programming, Knapsack
Problem
A gang has N members and can commit some of G possible crimes. Crime i needs group[i] members and makes profit[i]; a member who takes part in one crime cannot take part in another. A scheme is any subset of crimes that uses at most N members in total and makes at least MINPROFIT. Count the schemes modulo 1000000007. Use a knapsack over (members used, profit), capping the profit at MINPROFIT because any higher profit counts the same. Keep the counts in a 64-bit integer type (long long in C++, long in Java) and take the remainder after every addition and multiplication: adding or multiplying two remainders can be larger than a 32-bit int can hold (Python needs nothing special).
Input
The first line contains N, MINPROFIT and G. The second line contains group[0..G-1]. The third line contains profit[0..G-1].
Output
Print the number of profitable schemes modulo 1000000007.
Constraints
1 <= N <= 100; 0 <= MINPROFIT <= 100; 1 <= G <= 100; 1 <= group[i] <= 100; 0 <= profit[i] <= 100
Example input
5 3 2 2 2 2 3
Example output
2
Explanation
With 5 members, MINPROFIT = 3, groups 2 2 and profits 2 3, the schemes {crime 1} (profit 3) and {crimes 0 and 1} (profit 5, 4 members) qualify. Crime 0 alone makes only 2, so the answer is 2.