zig : update codes style && rust : add codes for chapter_backtracking. (#613)

* zig : update codes style

* rust : add codes for chapter_backtracking

* zig : update codes style
This commit is contained in:
sjinzh
2023-07-16 15:36:28 +08:00
committed by GitHub
parent 51a4c5089e
commit ead33ca863
17 changed files with 312 additions and 71 deletions
@@ -5,7 +5,7 @@
const std = @import("std");
// 零钱兑换:动态规划
fn coin_change_dp(comptime coins: []i32, comptime amt: usize) i32 {
fn coinChangeDP(comptime coins: []i32, comptime amt: usize) i32 {
comptime var n = coins.len;
comptime var max = amt + 1;
// 初始化 dp 表
@@ -34,7 +34,7 @@ fn coin_change_dp(comptime coins: []i32, comptime amt: usize) i32 {
}
// 零钱兑换:状态压缩后的动态规划
fn coin_change_dp_comp(comptime coins: []i32, comptime amt: usize) i32 {
fn coinChangeDPComp(comptime coins: []i32, comptime amt: usize) i32 {
comptime var n = coins.len;
comptime var max = amt + 1;
// 初始化 dp 表
@@ -66,11 +66,11 @@ pub fn main() !void {
comptime var amt: usize = 4;
// 动态规划
var res = coin_change_dp(&coins, amt);
var res = coinChangeDP(&coins, amt);
std.debug.print("凑到目标金额所需的最少硬币数量为 {}\n", .{res});
// 状态压缩后的动态规划
res = coin_change_dp_comp(&coins, amt);
res = coinChangeDPComp(&coins, amt);
std.debug.print("凑到目标金额所需的最少硬币数量为 {}\n", .{res});
_ = try std.io.getStdIn().reader().readByte();