In England the currency is made up of pound, £, and pence, p, and there are eight coins in general circulation:

1p, 2p, 5p, 10p, 20p, 50p, £1 (100p) and £2 (200p).

It is possible to make £2 in the following way:

1[Project Euler] Problem 31£1 + 1[Project Euler] Problem 3150p + 2[Project Euler] Problem 3120p + 1[Project Euler] Problem 315p + 1[Project Euler] Problem 312p + 3[Project Euler] Problem 311p

How many different ways can £2 be made using any number of coins?

典型的换硬币问题,典型的动态规划

#include <iostream>
usingnamespace std;

int main(){
intbase[] ={1,2,5,10,20,50,100,200};
int a[200][8] = {0};
a[
0][0]=1;
for(int i=1; i<200; i++){
for(int j=0; j<8; j++){
if(i+1-base[j] >0){
for(int k=0; k<=j; k++){
a[i][j]
+= a[i-base[j]][k];
}
}
if(i+1-base[j] ==0){
a[i][j]
+=1;
}
}
}
int sum =0;
for(int i=0; i<8; i++){
sum
+= a[199][i];
}
cout
<< sum << endl;
}

把每个面额的换法按最大的零钱面值分成8种情况

相关文章: