How to realize currency combination with Java
This article focuses on "how to use Java to achieve currency combination", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "how to use Java to achieve currency combination"!
I will give you six banknotes with denominations of 1, 5, 10, 20, 50 and 100 yuan. Assuming that the number of each currency is enough, write a program to find the number of different combinations that make up N yuan (N is a non-negative integer of 010000 yuan). Analyze first
1: suppose the sum of 100 and 50 coins is num, and num = 0pr 50, 100 pr 150, 50 * (Nmax 50)
The combinatorial number is Z1 (100x + 50y = the number of nonnegative integer solutions of num)
There are k sheets at 2: 20, karma 0pm 1pm 2pm 3pm. , (N-num) / 20
3: so the sum of these coins is v1andv5andv10 = N-num-20 * k.
The number of combinations is Z2 (10x+5y