From bd22ad9257b90dbeb2db60f5cdd6c591f6288e37 Mon Sep 17 00:00:00 2001 From: fw_qaq Date: 2023年4月13日 18:51:26 +0800 Subject: [PATCH 1/5] =?UTF-8?q?Update=200343.=E6=95=B4=E6=95=B0=E6=8B=86?= =?UTF-8?q?=E5=88=86.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...64346円225円260円346円213円206円345円210円206円.md" | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git "a/problems/0343.346円225円264円346円225円260円346円213円206円345円210円206円.md" "b/problems/0343.346円225円264円346円225円260円346円213円206円345円210円206円.md" index c2fbbdde68..4df6c41f4d 100644 --- "a/problems/0343.346円225円264円346円225円260円346円213円206円345円210円206円.md" +++ "b/problems/0343.346円225円264円346円225円260円346円213円206円345円210円206円.md" @@ -319,6 +319,29 @@ pub fn integer_break(n: i32) -> i32 { } ``` +贪心: + +```rust +impl Solution { + pub fn integer_break(mut n: i32) -> i32 { + match n { + 2 => 1, + 3 => 2, + 4 => 4, + 5.. => { + let mut res = 1; + while n> 4 { + res *= 3; + n -= 3; + } + res * n + } + _ => panic!("Error"), + } + } +} +``` + ### TypeScript ```typescript @@ -344,27 +367,6 @@ function integerBreak(n: number): number { }; ``` -### Rust - -```Rust -impl Solution { - fn max(a: i32, b: i32) -> i32{ - if a> b { a } else { b } - } - pub fn integer_break(n: i32) -> i32 { - let n = n as usize; - let mut dp = vec![0; n + 1]; - dp[2] = 1; - for i in 3..=n { - for j in 1..i - 1 { - dp[i] = Self::max(dp[i], Self::max(((i - j) * j) as i32, dp[i - j] * j as i32)); - } - } - dp[n] - } -} -``` - ### C ```c From 14c25f2eeff8e024f822485c4fbdfddcb0c3710e Mon Sep 17 00:00:00 2001 From: fwqaaq Date: 2023年4月28日 18:30:16 +0800 Subject: [PATCH 2/5] =?UTF-8?q?Update=20=E8=83=8C=E5=8C=85=E7=90=86?= =?UTF-8?q?=E8=AE=BA=E5=9F=BA=E7=A1=8001=E8=83=8C=E5=8C=85-1.md=20about=20?= =?UTF-8?q?rust?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...47241円20001円350円203円214円345円214円205円-1.md" | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git "a/problems/350円203円214円345円214円205円347円220円206円350円256円272円345円237円272円347円241円20001円350円203円214円345円214円205円-1.md" "b/problems/350円203円214円345円214円205円347円220円206円350円256円272円345円237円272円347円241円20001円350円203円214円345円214円205円-1.md" index c45fc3d302..c25252488a 100644 --- "a/problems/350円203円214円345円214円205円347円220円206円350円256円272円345円237円272円347円241円20001円350円203円214円345円214円205円-1.md" +++ "b/problems/350円203円214円345円214円205円347円220円206円350円256円272円345円237円272円347円241円20001円350円203円214円345円214円205円-1.md" @@ -573,6 +573,39 @@ object Solution { } ``` +### Rust + +```rust +pub struct Solution; + +impl Solution { + pub fn wei_bag_problem1(weight: Vec, value: Vec, bag_size: usize) -> usize { + let mut dp = vec![vec![0; bag_size + 1]; weight.len()]; + for j in weight[0]..=weight.len() { + dp[0][j] = value[0]; + } + + for i in 1..weight.len() { + for j in 0..=bag_size { + match j < weight[i] { + true => dp[i][j] = dp[i - 1][j], + false => dp[i][j] = dp[i - 1][j].max(dp[i - 1][j - weight[i]] + value[i]), + } + } + } + dp[weight.len() - 1][bag_size] + } +} + +#[test] +fn test_wei_bag_problem1() { + println!( + "{}", + Solution::wei_bag_problem1(vec![1, 3, 4], vec![15, 20, 30], 4) + ); +} +``` +

From e6ad637e6475c73766f401b052a1c523d171d059 Mon Sep 17 00:00:00 2001 From: fwqaaq Date: 2023年4月28日 18:50:56 +0800 Subject: [PATCH 3/5] =?UTF-8?q?Update=20=E8=83=8C=E5=8C=85=E7=90=86?= =?UTF-8?q?=E8=AE=BA=E5=9F=BA=E7=A1=8001=E8=83=8C=E5=8C=85-2.md=20about=20?= =?UTF-8?q?rust?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...47241円20001円350円203円214円345円214円205円-2.md" | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git "a/problems/350円203円214円345円214円205円347円220円206円350円256円272円345円237円272円347円241円20001円350円203円214円345円214円205円-2.md" "b/problems/350円203円214円345円214円205円347円220円206円350円256円272円345円237円272円347円241円20001円350円203円214円345円214円205円-2.md" index baa4107f58..1ce90440b6 100644 --- "a/problems/350円203円214円345円214円205円347円220円206円350円256円272円345円237円272円347円241円20001円350円203円214円345円214円205円-2.md" +++ "b/problems/350円203円214円345円214円205円347円220円206円350円256円272円345円237円272円347円241円20001円350円203円214円345円214円205円-2.md" @@ -406,6 +406,34 @@ object Solution { } ``` +### Rust + +```rust +pub struct Solution; + +impl Solution { + pub fn wei_bag_problem2(weight: Vec, value: Vec, bag_size: usize) -> usize { + let mut dp = vec![0; bag_size + 1]; + for i in 0..weight.len() { + for j in (weight[i]..=bag_size).rev() { + if j>= weight[i] { + dp[j] = dp[j].max(dp[j - weight[i]] + value[i]); + } + } + } + dp[dp.len() - 1] + } +} + +#[test] +fn test_wei_bag_problem2() { + println!( + "{}", + Solution::wei_bag_problem1(vec![1, 3, 4], vec![15, 20, 30], 4) + ); +} +``` +

From d2650cc436980c2553003e3c7bdba2e8579aa53b Mon Sep 17 00:00:00 2001 From: fwqaaq Date: 2023年4月28日 18:51:38 +0800 Subject: [PATCH 4/5] =?UTF-8?q?Update=20problems/=E8=83=8C=E5=8C=85?= =?UTF-8?q?=E7=90=86=E8=AE=BA=E5=9F=BA=E7=A1=8001=E8=83=8C=E5=8C=85-2.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...272円345円237円272円347円241円20001円350円203円214円345円214円205円-2.md" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/problems/350円203円214円345円214円205円347円220円206円350円256円272円345円237円272円347円241円20001円350円203円214円345円214円205円-2.md" "b/problems/350円203円214円345円214円205円347円220円206円350円256円272円345円237円272円347円241円20001円350円203円214円345円214円205円-2.md" index 1ce90440b6..3b798334a6 100644 --- "a/problems/350円203円214円345円214円205円347円220円206円350円256円272円345円237円272円347円241円20001円350円203円214円345円214円205円-2.md" +++ "b/problems/350円203円214円345円214円205円347円220円206円350円256円272円345円237円272円347円241円20001円350円203円214円345円214円205円-2.md" @@ -429,7 +429,7 @@ impl Solution { fn test_wei_bag_problem2() { println!( "{}", - Solution::wei_bag_problem1(vec![1, 3, 4], vec![15, 20, 30], 4) + Solution::wei_bag_problem2(vec![1, 3, 4], vec![15, 20, 30], 4) ); } ``` From 18a16f9faffb7b796d174fb150e3dd601f6f82f4 Mon Sep 17 00:00:00 2001 From: Jia Tan Date: 2023年4月30日 20:24:32 +0000 Subject: [PATCH 5/5] Ignore .DS_Store files. --- .DS_Store | Bin 6148 -> 0 bytes .gitignore | 1 + 2 files changed, 1 insertion(+) delete mode 100644 .DS_Store create mode 100644 .gitignore diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index da03c1c1b207c3ee04079084ecb15dcfff97ef95..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK%}T>S5T317Q;OJwLXQhx3-<3)^bl)(0v4`psf{t$m}x1utbhSVD*@yHz(SRn%3w1`N_?k*PTX z=s*u5cO3N-(d77z49It9K_3Pnz=e13&kcl&V-IdW@S|a|_{35R>BXgGloVwt;#QN%@Vis8VsHj`Xe9O(bW6^; z=;?2>^71?{rY9N=vv=!y_4uZF|F|A+0!!OY6cR47cXj`MRB4$Rg_Eiph0d}LrjcXRUo z-}}7&|CmHQVt^R

AltStyle によって変換されたページ (->オリジナル) /