Re: [閒聊] 每日LeetCode已回收

看板Marginalman作者 (南爹摳打)時間1年前 (2024/02/03 15:00), 編輯推噓2(200)
留言2則, 2人參與, 1年前最新討論串648/719 (看更多)
練習一下DP C# code: public class Solution { public int MaxSumAfterPartitioning(int[] arr, int k) { int n = arr.Length; int[] dp = new int[n+1]; int max; for (int i=1; i<=n; i++) { max = 0; for (int j=1; j<=Math.Min(i,k); j++) { max = Math.Max(max, arr[i-j]); dp[i] = Math.Max(dp[i], dp[i-j] + max*j); } } return dp[n]; } } -- (づ′・ω・)づ -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 61.220.51.52 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1706943628.A.EE2.html

02/03 15:04, 1年前 , 1F
大師
02/03 15:04, 1F

02/03 15:05, 1年前 , 2F
大師
02/03 15:05, 2F
文章代碼(AID): #1blUICxY (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1blUICxY (Marginalman)