From 6e5c4c6eb2820bc2f842e26b1633bfbe767b1161 Mon Sep 17 00:00:00 2001 From: Coin de Gamma Date: Sun, 12 Nov 2023 09:49:52 +0000 Subject: [PATCH] 031 ok --- 031/main.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 031/main.rs 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); +} +