当前位置:网站首页>1255. 得分最高的单词集合 状态压缩动态规划
1255. 得分最高的单词集合 状态压缩动态规划
2022-07-17 02:15:00 【钰娘娘】
方法:动态规划
- 计数,映射到26个字母
- 填充单个单词的得分情况,顺便验证能否用现有字符组成单词
- 尝试继续填写,dp前26代表占用字母数目,第27位代表得分
class Solution {
public long sellingWood(int m, int n, int[][] prices) {
long[][] dp = new long[m+1][n+1];
for(int [] price:prices){
dp[price[0]][price[1]]=price[2];
}
for(int i = 1; i <= m; i++){
for(int j = 1; j <= n; j++){
for(int t = 0 ; t<=j;t++) dp[i][j]=Math.max(dp[i][j],dp[i][t]+dp[i][j-t]);
for(int t = 0 ; t<=i;t++) dp[i][j]=Math.max(dp[i][j],dp[t][j]+dp[i-t][j]);
}
}
return dp[m][n];
}
}时间复杂度:O(n*2^n)
空间复杂度:O(2^n)
边栏推荐
猜你喜欢

Chapter II linear table

MySQL 增删查改(基础)

NIM boben problem

Frequency school and Bayes school

一种鲁棒变形卷积神经网络图像去噪

鼠标滑动两张图片前后对比js插件

Neural network learning notes 2.2 -- write a simple convolution neural network image classifier with MATLAB

options has an unknown property ‘before‘

Through openharmony compatibility evaluation, the big brother development board and rich teaching and training resources have been ready

central limit theorem
随机推荐
Thinkphp5.0模型操作使用page进行分页
企业钟情于混合 App 开发,小程序容器技术能让效率提升 100%
第二章 线性表
Ouvrir le cvsharp d'ai pour trouver une petite image (version de cas)
Boston house price analysis assignment summary
[2016 CCPC 杭州J] Just a Math Problem (莫比乌斯反演)
已经25岁了还是一事无成,找不到出路怎么办?做自媒体怎么样?
Chapter II: news topic classification tasks
Penetration test-01 information collection
为什么越来越多人开始选择过“低配生活”?
【LeetCode】346. Moving average in data flow
Chapter I Introduction
web语义化(强调标签-em-斜体)(重点强调标签-strong-粗体)(自定义列表:dl、dt、dd)
Method of realizing horizontal and vertical centering of unknown width and height elements
HRNet
MySQL addition, deletion, query and modification (basic)
Matlab在线性代数中的应用
Oracle queries the maximum partition of non self growing partition
Oracle queries the host name and the corresponding IP address
神器网站目录,全都是刚需好用的网站