当前位置:网站首页>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 :
边栏推荐
- 一文详解JackSon配置信息
- Still worried about missing measurements? Let's use Jacobo to calculate the code coverage
- 安裝ImageMagick7.1庫以及php的Imagick擴展
- 熬夜整理出的软件测试【高频】面试题大全(2022最新)
- 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
- Understanding openstack network
- 不忘初心
- 存在安全隐患 路虎召回部分混动揽运
- 【我的OpenGL学习进阶之旅】OpenGL的坐标系的学习笔记
- Paper: Google TPU
猜你喜欢
![Software test [high frequency] interview questions sorted out by staying up late (latest in 2022)](/img/33/2c2256fd98b908ddaf5573f644ad7f.png)
Software test [high frequency] interview questions sorted out by staying up late (latest in 2022)

运营商5G用户渗透远远比4G慢,5G的普及还得看中国广电
![[application recommendation] the hands-on experience and model selection suggestions of apifox & apipost in the recent fire](/img/dd/24df91a8a1cf1f1b9ac635abd6863a.png)
[application recommendation] the hands-on experience and model selection suggestions of apifox & apipost in the recent fire

MongoDB入门实战教程:学习总结目录

SIGGRAPH 2022 | 真实还原手部肌肉,数字人双手这次有了骨骼、肌肉、皮肤
![[C language questions -- leetcode 12 questions] take you off and fly into the garbage](/img/ca/a356a867f3b7ef2814080fb76b9bfb.png)
[C language questions -- leetcode 12 questions] take you off and fly into the garbage

Intelij 中的 Database Tools可以连接但是无法显示SCHEMA, TABLES

Using alicloud RDS for SQL Server Performance insight to optimize database load - first understanding of performance insight

一文理解OpenStack网络

Wi-Fi 7 来啦,它到底有多强?
随机推荐
Understanding openstack network
SIGGRAPH 2022 | 真实还原手部肌肉,数字人双手这次有了骨骼、肌肉、皮肤
一文详解JackSon配置信息
构建Go命令行程序工具链
MySQL toolset: the official export tool mysqlpump
Mysql之Binlog
Remember: never use UTF-8 in MySQL
Jenkins的便捷式安装
[log service CLS] Tencent cloud log4j/logback log collection best practices
还在担心漏测吗?快来使用jacoco统计下代码覆盖率
2021-05-04: given a non negative integer C, you need to judge whether there are two integers a and B, so that a*a+b*b=c.
【我的OpenGL学习进阶之旅】OpenGL的坐标系的学习笔记
From practical teaching to competition exercise, Tencent experts personally teach Ti-One platform operation strategy!
运营商5G用户渗透远远比4G慢,5G的普及还得看中国广电
几种常见的DoS攻击
Istio FAQ: return 426 status code
Wi-Fi 7 来啦,它到底有多强?
VNC Viewer方式的远程连接树莓派
Intelij 中的 Database Tools可以连接但是无法显示SCHEMA, TABLES
The penetration of 5g users of operators is far slower than that of 4G. The popularity of 5g still depends on China Radio and television