changeset 13:d919809de7a0

rodcutting max prod
author Lewin Bormann <lbo@spheniscida.de>
date Sun, 19 Mar 2023 21:58:20 +0100
parents c8e1da3603ea
children 3cf1e46d317e
files dynprog.cc
diffstat 1 files changed, 12 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/dynprog.cc	Sun Mar 19 18:13:55 2023 +0100
+++ b/dynprog.cc	Sun Mar 19 21:58:20 2023 +0100
@@ -289,7 +289,7 @@
     return wildcard_matches(pattern.begin(), pattern.end(), str.begin(), str.end());
 }
 
-void eval_wildcard_matches() {
+void evaluate_wildcard_matches() {
     vector<pair<string,string>> tests{
         {"xyxzzxy", "x***y"},
         {"xyxzzxy", "x***x"},
@@ -303,6 +303,16 @@
     }
 }
 
+// TODO: store cutting way
+int rodcutting_prod_max(int length) {
+    if (length <= 1) return 1;
+    int max_len = 0;
+    for (int this_part = length; this_part > 0; this_part--) {
+        max_len = max(max_len, this_part * rodcutting_prod_max(length-this_part));
+    }
+    return max_len;
+}
+
 int lcss_main(void) {
 
     vector<int> a{1, 6, 2, -1, 3, 55, 2, 4, 23, 5, 6, 7, 8, 9, 10};
@@ -322,6 +332,6 @@
 }
 
 int main(void) {
-    eval_wildcard_matches();
+    fmt::print("{}\n", rodcutting_prod_max(4));
     return 0;
 }