diff --git a/031/main.rs b/031/main.rs new file mode 100644 index 0000000..b80b577 --- /dev/null +++ b/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); +} +