Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How does Java solve the problem of robbing houses?

Shulou Source: shulou.com Published: 2022-06-01 10:50:51 10月03日 Update

This article mainly explains "how to solve the problem of home robbery by Java". Interested friends might as well take a look. The method introduced in this paper is simple, fast and practical. Next, let's let the editor take you to learn "how to solve the problem of robbery by Java".

If you want to rob the nth house, you can't rob the nth house, so the money you get from robbing the nth house is the money of the nth family plus the most money obtained by the former Nmai 2 families, that is, f (nmur2) + nums (n). If you don't rob the nth house, the maximum profit is f (nMuth1). We have to go to the larger one, so the dynamic transfer equation is:

F (n) = max (nums [n] + f (nmur2), f (nmur1))

Package mainimport "fmt" func max (return b int) int {if a > b {return a} return b} func rob (nums [] int) int {if len (nums) = 0 {return 0} if len (nums) = 1 {return nums [0]} dp: = make ([] int,len (nums) dp [0] = nums [0] dp [1] = max (nums [0]) Nums [1]) maxVal: = dp [1] for iRu 2 I

Tags: Fighting problems content learning practical deeper maximum greater interest dynamic practical practical that is necessity simple operation benefits methods equations more friends. Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Apple Shulou Technology Huawei MySQL