The price (full backpack)

Source: Internet
Author: User

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 ;}


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.