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