当前位置:网站首页>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 :
边栏推荐
- PHP export data as excel table
- Vim编辑器的最常用的用法
- [tke] multiple ingress controllers are used in the cluster
- Istio FAQ: return 426 status code
- Wi-Fi 7 来啦,它到底有多强?
- 构建Go命令行程序工具链
- 设备通过国标GB28181接入EasyCVR平台,出现断流情况该如何解决?
- Intelij 中的 Database Tools可以连接但是无法显示SCHEMA, TABLES
- April 23, 2021: there are n cities in the TSP problem, and there is a distance between any two cities
- MySQL 开发规范
猜你喜欢

构建Go命令行程序工具链

Recommend several super practical data analysis tools

Apple is no match for the longest selling mobile phone made in China, and has finally brought back the face of the domestic mobile phone

60 个神级 VS Code 插件!!

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

Using oasis to develop a hop by hop (I) -- Scene Building
![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]

Still worried about missing measurements? Let's use Jacobo to calculate the code coverage
![[my advanced OpenGL learning journey] learning notes of OpenGL coordinate system](/img/21/48802245fea2921fd5e4a9a2d9ad18.jpg)
[my advanced OpenGL learning journey] learning notes of OpenGL coordinate system

为什么企业实施WMS仓储管理系统很容易失败
随机推荐
Solution of intelligent all in one machine in expressway service area
2021-04-24: handwriting Code: topology sorting.
great! The novel website project is completely open source
日志记录真没你想的那么简单
构建Go命令行程序工具链
Mysql之Binlog
60 个神级 VS Code 插件!!
Wi-Fi 7 来啦,它到底有多强?
The first in China! Tencent cloud key management system passes password application verification test
Nifi from introduction to practice (nanny level tutorial) - environment
2021-04-22: given many line segments, each line segment has two numbers [start, end],
我与“Apifox”的网络情缘
10 hands-free idea plug-ins. These codes do not need to be written (the second bullet)
Firefox browser uses plug-ins to set up proxy
PHP application container deployment practice
From practical teaching to competition exercise, Tencent experts personally teach Ti-One platform operation strategy!
Istio FAQ: region awareness does not take effect
Golang+redis distributed mutex
clang: warning: argument unused during compilation: ‘-no-pie‘ [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: ‘-no-pie‘ [-Wunused-command-line-argument]