当前位置: 首页 > wzjs >正文

建设网站是什么旅游网站开发项目介绍

建设网站是什么,旅游网站开发项目介绍,搭建html5网站,网站开发工作室挣钱吗问题背景 给你一个下标从 0 0 0 开始的 二进制 字符串 f l o o r floor floor,它表示地板上砖块的颜色。 f l o o r [ i ] floor[i] floor[i] 为 ‘0’ 表示地板上第 i i i 块砖块的颜色是 黑色 。 f l o o r [ i ] floor[i] floor[i] 为’1’ 表示地板上第 i …

问题背景

给你一个下标从 0 0 0 开始的 二进制 字符串 f l o o r floor floor,它表示地板上砖块的颜色。

  • f l o o r [ i ] floor[i] floor[i] 为 ‘0’ 表示地板上第 i i i 块砖块的颜色是 黑色
  • f l o o r [ i ] floor[i] floor[i] 为’1’ 表示地板上第 i i i 块砖块的颜色是 白色

同时给你 n u m C a r p e t s numCarpets numCarpets c a r p e t L e n carpetLen carpetLen。你有 n u m C a r p e t s numCarpets numCarpets黑色 的地毯,每一条 黑色 的地毯长度都为 c a r p e t L e n carpetLen carpetLen 块砖块。请你使用这些地毯去覆盖砖块,使得未被覆盖的剩余 白色 砖块的数目 最小 。地毯相互之间可以覆盖。
请你返回没被覆盖的白色砖块的 最少 数目。

数据约束

  • 1 ≤ c a r p e t L e n ≤ f l o o r . l e n g t h ≤ 1000 1 \le carpetLen \le floor.length \le 1000 1carpetLenfloor.length1000
  • f l o o r [ i ] floor[i] floor[i]要么是 ‘0’ ,要么是 ‘1’ 。
  • 1 ≤ n u m C a r p e t s ≤ 1000 1 \le numCarpets \le 1000 1numCarpets1000

解题过程

比较标准的动态规划模板题,关键是定义清楚状态,这里用 i i i表示剩余的地毯数量, j j j表示剩余的砖块数量。
空间优化的做法没完全理解,先不要求。

具体实现

递归

class Solution {public int minimumWhiteTiles(String floor, int numCarpets, int carpetLen) {int n = floor.length();int[][] memo = new int[numCarpets + 1][n];for (int[] row : memo) {Arrays.fill(row, -1);}return dfs(numCarpets, n - 1, floor.toCharArray(), memo, carpetLen);}private int dfs(int i, int j, char[] floor, int[][] memo, int carpetLen) {if (j < carpetLen * i) {return 0;}if (memo[i][j] != -1) {return memo[i][j];}int res = dfs(i, j - 1, floor, memo, carpetLen) + floor[j] - '0';if (i > 0) {res = Math.min(res, dfs(i - 1, j - carpetLen, floor, memo, carpetLen));}return memo[i][j] = res;}
}

递推

class Solution {public int minimumWhiteTiles(String floor, int numCarpets, int carpetLen) {char[] chF = floor.toCharArray();int n = chF.length;int[][] dp = new int[numCarpets + 1][n];dp[0][0] = chF[0] - '0';for (int j = 1; j < n; j++) {dp[0][j] = dp[0][j - 1] + chF[j] - '0';}for (int i = 1; i <= numCarpets; i++) {for (int j = carpetLen * i; j < n; j++) {dp[i][j] = Math.min(dp[i][j - 1] + chF[j] - '0', dp[i - 1][j - carpetLen]);}}return dp[numCarpets][n - 1];}
}

文章转载自:

http://00000000.znkLs.cn
http://00000000.znkLs.cn
http://00000000.znkLs.cn
http://00000000.znkLs.cn
http://00000000.znkLs.cn
http://00000000.znkLs.cn
http://00000000.znkLs.cn
http://00000000.znkLs.cn
http://00000000.znkLs.cn
http://00000000.znkLs.cn
http://00000000.znkLs.cn
http://00000000.znkLs.cn
http://00000000.znkLs.cn
http://00000000.znkLs.cn
http://00000000.znkLs.cn
http://00000000.znkLs.cn
http://00000000.znkLs.cn
http://00000000.znkLs.cn
http://00000000.znkLs.cn
http://00000000.znkLs.cn
http://00000000.znkLs.cn
http://00000000.znkLs.cn
http://00000000.znkLs.cn
http://00000000.znkLs.cn
http://00000000.znkLs.cn
http://00000000.znkLs.cn
http://00000000.znkLs.cn
http://00000000.znkLs.cn
http://00000000.znkLs.cn
http://00000000.znkLs.cn
http://www.dtcms.com/wzjs/618614.html

相关文章:

  • 从哪方面建设网站中国科技成就按时间顺序
  • 创业网站开发软文写作技巧有哪些
  • 做网站备案实名需要钱吗室内装修设计软件排行榜
  • 彩票网站开发系统如何搭建荆州网站建设推荐
  • 康复中心网站建设方案盐田做网站
  • 怎样投网站广告oa办公管理系统哪个好
  • 广西网络公司网站建设wordpress大前端主题免费试用
  • 做网站的收入开源的低代码开发平台
  • 做彩票网站犯法不网络开发软件
  • 广告公司网站官网txt 发布 wordpress
  • 珠海网站建设费用中山软件开发公司
  • 网站移动端怎么做百度搜题网页版入口
  • 做网站都需要准备什么软件企业邮箱号是什么样的格式
  • 网站如何建设个人主页经典句子
  • 高端定制网站建设公司字节跳动直播开放平台
  • 适合做公司网站的cms邯郸网站建设产品介绍
  • 中国林业工程建设协会官方网站网页设计制作方案
  • 色轮 网站江西萍乡做网站公司
  • 电子产品网站建设模板少儿编程十大培训机构加盟
  • 网页技术与网站开发分析报告湖州网络推广竞价
  • 可以做没有水印的视频网站网站配色
  • 网站客户运营一个人可做几次网站备案
  • 流量购买网站营销策划公司的经营范围
  • 电子商务网站建设 试卷四川网站建设那家好
  • 网站建设优化服务咨询易货网站开发
  • 福州专业网站设计如何在自己网站上做支付宝吗
  • 网站建设属开票核定税种软件园二期做网站的公司有哪些
  • 投票网站怎么制作私人做网站费用
  • 域名网站建设教程开发一个app需要多少钱
  • 一流的盘锦网站建设h5网站源码