You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
514 B

12 months ago
fn cs(n: u32, cl: usize) -> u32 {
let coins = [1, 2, 5, 10, 20, 50, 100, 200];
if n == 0 { return 1; }
if cl == 0 { return 1; }
let mut res = cs(n, cl - 1);
//println!("init {}/{}/{}", n, cl, res);
let mc = coins[cl];
let mut m = n;
//println!("m vs mc: {}/{}", m, mc);
while m >= mc {
res += cs(m - mc, cl - 1);
//println!("res({}, {})+= {}", m-mc, cl-1, res);
m -= mc;
}
res
}
fn main() {
let res = cs(200, 7);
println!("{}", res);
}