Code[vs] 1297 Coins

Source: Internet
Author: User

Title Description Description

We know that even a coin of the same denomination may have a different weight because it is influenced by many factors, including manufacturing processes and processes. But the weight of a coin of any denomination is always within a certain range. The weight range of the coins is now known for all denominations. Given the total weight of a pile of coins, ask how different the total value of this pile of coins might be. Example: The weight of a dime is known to be between 19 and 21, and the weight of the five-point coin is between 40 and 43. There is a pile of coins with a total weight of 99. Then it can be made up of 4 weights of 20, consisting of 1 pieces of a dime with a weight of 19, the total value is 5 cents, or it can be made up of 1 five-point coins of 42 weight and 3 cents of 19, with a total value of 8 cents, or a 2-carat coin with 40 weight and 1 cents of a dime, Its total value is 1.1 yuan. So there are 3 different possibilities for the total value of this pile of coins.

Enter a description input Description

The first line is an integer w (10<=w<=100) that represents the total weight of all coins. The second line is an integer n (1<=n<=7) that represents the total number of coins of different denominations. The next n lines are 3 integers per line, which in turn represent the nominal value of the coin, the minimum possible weight and the maximum possible weight. The nominal value of the coin is not more than 50, the minimum weight is not less than 2 and the maximum weight is 100. The difference between the maximum weight and the minimum weight is not more than 30.

outputs description output Description

Including only one row indicates how many different possibilities the total value of this pile of coins is.

sample input to sample

99

2

1 19 21

5 40 43

Sample output Sample outputs

3

dp+ recursion, this problem in the memory of the search there, do not know the two-dimensional array records, but with one-dimensional in the dead push. This question also makes me realize how many parameters the DP function has, and it should be remembered with a few dimensions of the array.



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Code[vs] 1297 Coins

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.