Coin de Gamma
1 year ago
1 changed files with 22 additions and 0 deletions
@ -0,0 +1,22 @@
|
||||
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); |
||||
} |
||||
|
Loading…
Reference in new issue