当前位置:网站首页>2021-04-28: force buckle 546, remove the box. Give some boxes of different colors
2021-04-28: force buckle 546, remove the box. Give some boxes of different colors
2022-06-24 15:55:00 【Fuda scaffold constructor's daily question】
2021-04-28: Power button 546, Remove the box . Give some boxes of different colors , The color of the box is represented by numbers , That is, different numbers represent different colors . You will go through several rounds of operations to remove the box , Until all the boxes are removed . Each round you can remove a continuous with the same color k Boxes (k >= 1), After such a round, you will get k * k Integral points . When you remove all the boxes , Find the maximum points you can get and .
Fuda answer 2021-04-28:
Dynamic programming .
The code to use golang To write . The code is as follows :
package main
import (
"fmt"
)
func main() {
arr := []int{2, 2, 2}
ret := removeBoxes2(arr)
fmt.Println(ret)
}
func removeBoxes2(boxes []int) int {
N := len(boxes)
dp := make([][][]int, N)
for i := 0; i < N; i++ {
dp[i] = make([][]int, N)
for j := 0; j < N; j++ {
dp[i][j] = make([]int, N)
}
}
ans := process2(boxes, 0, N-1, 0, dp)
return ans
}
func process2(boxes []int, L int, R int, K int, dp [][][]int) int {
if L > R {
return 0
}
if dp[L][R][K] > 0 {
return dp[L][R][K]
}
// Find the beginning ,
// 1,1,1,1,1,5
// 3 4 5 6 7 8
// !
last := L
for last+1 <= R && boxes[last+1] == boxes[L] {
last++
}
// K individual 1 (K + last - L) last
pre := K + last - L
ans := (pre+1)*(pre+1) + process2(boxes, last+1, R, 0, dp)
for i := last + 2; i <= R; i++ {
if boxes[i] == boxes[L] && boxes[i-1] != boxes[L] {
ans = getMax(ans, process2(boxes, last+1, i-1, 0, dp)+process2(boxes, i, R, pre+1, dp))
}
}
dp[L][R][K] = ans
return ans
}
func getMax(a int, b int) int {
if a > b {
return a
} else {
return b
}
}The results are as follows :
边栏推荐
- How to expand disk space on AWS host
- Implement Domain Driven Design - use ABP framework - domain logic & application logic
- Remote connection raspberry pie in VNC Viewer Mode
- 60 divine vs Code plug-ins!!
- Solution to the problem that FreeRTOS does not execute new tasks
- 【面试高频题】难度 3/5,可直接构造的序列 DP 题
- Efficient tools commonly used by individuals
- Nifi from introduction to practice (nanny level tutorial) - environment
- Nature刊登量子计算重大进展:有史以来第一个量子集成电路实现
- [interview high frequency questions] sequential DP questions with difficulty of 3/5 and direct construction
猜你喜欢

The equipment is connected to the easycvr platform through the national standard gb28181. How to solve the problem of disconnection?
![clang: warning: argument unused during compilation: ‘-no-pie‘ [-Wunused-command-line-argument]](/img/f0/42f394dbc989d381387c7b953d2a39.jpg)
clang: warning: argument unused during compilation: ‘-no-pie‘ [-Wunused-command-line-argument]

国产芯片的赶超,让美国手机芯片龙头高通害怕了,出招应对竞争

国产最长寿的热销手机,苹果也不是对手,总算让国产手机找回面子

CAP:多重注意力机制,有趣的细粒度分类方案 | AAAI 2021

Wi-Fi 7 来啦,它到底有多强?

The catch-up of domestic chips has scared Qualcomm, the leader of mobile phone chips in the United States, and made moves to cope with the competition

Linux记录-4.22 MySQL5.37安装(补充)

Still worried about missing measurements? Let's use Jacobo to calculate the code coverage

Solution to the problem that FreeRTOS does not execute new tasks
随机推荐
微信公众号调试与Natapp环境搭建
【Prometheus】4. Monitoring cases
【面试高频题】难度 3/5,可直接构造的序列 DP 题
Linux记录-4.22 MySQL5.37安装(补充)
2021-04-18: given a two-dimensional array matrix, the value in it is either 1 or 0,
Several common DoS attacks
在Gradle 中对Junit5 测试框架引用
Learning these 10 kinds of timed tasks, I'm a little floating
leetcode 139. Word break word split (medium)
MongoDB入門實戰教程:學習總結目錄
The first in China! Tencent cloud key management system passes password application verification test
Using alicloud RDS for SQL Server Performance insight to optimize database load - first understanding of performance insight
一文详解JackSon配置信息
MySQL toolset: the official performance testing tool mysqlslap
Network engineers must know the network essence knowledge!
2021-04-25: given an array arr and a positive number m, the
一文理解OpenStack网络
Logging is not as simple as you think
Linux record -4.22 MySQL 5.37 installation (supplementary)
Ascinema with asciicast2gif for efficient command line terminal recording