In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "how to achieve maximum continuous interval and dynamic programming in Python". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Problem description: given an integer sequence An of length N, please select a continuous subsequence (which can be 0) so that the sum of this segment is maximum. You can only get 10 points (equal to no writing) in the OJ system and present the code below:
N=int (input (). Strip ()) A=list (map (int) Input (). Strip (). Split () # input format A.insert (0 0) # initialize N+=1dp=list (range (N)) # dp [I] represents the sequence maximum value dp [0] = 0if max (A) 0 else print (0) # if the maximum subsequence is less than 0, then simply do not take 0 greater than the negative number # to say in detail:, # dp [I] represents the maximum of the subsequence ending with the I th digit # Analysis sets the I th digit as a [I] ① dp [I] = a [I] or (the sum of the interval sequence ending with a [I] is S1 S2,s3...sn So dp [I-1] = max (s1mems2pr .sn) dp [I] = max (S1 + a [I], s2 + a [I]... sn+ a [I]) = a [I] + max (s1J s2... sn) # that is, ② dp [I] = a [I] + DP [1] # so there are two types of subsequences ending with the first number, so a larger value can be taken to introduce the content of "how to achieve maximum continuous interval and dynamic programming in Python". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.