In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article focuses on "how to use golang to find the minimum score for merging n stones into a pile". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use golang to find the minimum score for merging n stones into a pile.
The code is written in golang. The code is as follows:
Package mainimport ("fmt"math") func main () {arr: = [] int {1,4,2,3} ret: = StoneMerge (arr) fmt.Println (ret)} func sum (arr [] int) [] int {N: = len (arr) s: = make ([] int, Noni1) s [0] = for I: = 0; I
< N; i++ { s[i+1] = s[i] + arr[i] } return s}func w(s []int, l int, r int) int { return s[r+1] - s[l]}func StoneMerge(arr []int) int { if len(arr) < 2 { return 0 } N := len(arr) s := sum(arr) dp := make([][]int, N) for i := 0; i < N; i++ { dp[i] = make([]int, N) } best := make([][]int, N) for i := 0; i < N; i++ { best[i] = make([]int, N) } for i := 0; i < N-1; i++ { best[i][i+1] = i dp[i][i+1] = w(s, i, i+1) } for L := N - 3; L >= 0; for-{for R: = L + 2; R < N; R + {next: = math.MaxInt64 choose: =-1 for leftEnd: = best [L] [R Mel 1]; leftEnd
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.