Question: The price (full backpack)
The same is the issue of making money, but the number of coins used for collecting money must be counted.
Solution: Change 1-is fixed here. In addition, the maximum value of N is 300, so the number of coins with N is N. Given p, q is less than 1100, so if it is greater than 300, no computation is required, it must be 0. DP [I] [J]: Use J coins to make up the number of I. And the change is fixed, so we can calculate the DP [N] [1. N] of 1 -- 300 at the beginning, and then query it directly. Note that N can be equal to 0.
Code:
# Include <cstdio> # include <cstring> const int n = 305; typedef long ll; ll DP [N] [N]; int min (const int, const int B) {return a <B? A: B;} void Init () {DP [0] [0] = 1; for (INT I = 1; I <= 300; I ++) {for (Int J = I; j <= 300; j ++) {for (int K = 0; k <= J-I; k ++) DP [J] [k + 1] + = DP [J-I] [k] ;}} int main () {int N, L1, L2; int X; char ch; Init (); While (scanf ("% d", & N )! = EOF) {scanf ("% C", & Ch); L1 = 0; L2 = 300; If (Ch! = '\ N') {scanf ("% d % C", & X, & Ch); If (Ch! = '\ N') {L1 = x; scanf ("% d", & l2) ;}elsel2 = x ;}if (L1 <= 300) {If (L2> 300) L2 = 300; ll ans = 0; For (INT I = L1; I <= L2; I ++) ans + = DP [N] [I]; printf ("% LLD \ n", ANS);} else printf ("0 \ n");} return 0 ;}