Browse Source

031 ok

master
Coin de Gamma 12 months ago
parent
commit
6e5c4c6eb2
  1. 22
      031/main.rs

22
031/main.rs

@ -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…
Cancel
Save