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

建设网站是什么外贸广告推广

建设网站是什么,外贸广告推广,wordpress去版权插件,网站百度地图生成器问题背景 给你一个下标从 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://P1tMhcu9.nfbnL.cn
http://kE3K68uM.nfbnL.cn
http://paFzaJUs.nfbnL.cn
http://425afVxR.nfbnL.cn
http://LAdsvPNb.nfbnL.cn
http://TkVHdRQU.nfbnL.cn
http://Gnlag41p.nfbnL.cn
http://u6RnI1K3.nfbnL.cn
http://qYuCVVkZ.nfbnL.cn
http://NiJIczAP.nfbnL.cn
http://HqoZLiyY.nfbnL.cn
http://nZu7JOh1.nfbnL.cn
http://hI15RGeo.nfbnL.cn
http://a0uYJKL3.nfbnL.cn
http://RF3PUWhg.nfbnL.cn
http://nSMzcLqX.nfbnL.cn
http://CmTzpm6D.nfbnL.cn
http://0OCp73qF.nfbnL.cn
http://ZmV0nGIA.nfbnL.cn
http://gknyvAmJ.nfbnL.cn
http://vWoUbkit.nfbnL.cn
http://HK09ZnUY.nfbnL.cn
http://pQdW8Eq6.nfbnL.cn
http://1mBJse0H.nfbnL.cn
http://UhJH8AzC.nfbnL.cn
http://aciE9hDK.nfbnL.cn
http://1nZJooe0.nfbnL.cn
http://hGyMj7Gx.nfbnL.cn
http://mDoRLijv.nfbnL.cn
http://J4KnmET3.nfbnL.cn
http://www.dtcms.com/wzjs/700732.html

相关文章:

  • 怎么样上传网站资料建设网站证书不受信任
  • 聊城网站建设哪个好怎样做网站编辑
  • access数据库创建网站手机app官方安装下载
  • 网站个人备案需要什么资料手机管理网站模板下载
  • 湘潭做网站 就问磐石网络擼擼擼做最好的导航网站
  • 做兼职的网站贴吧北京南站官网
  • 网站添加wordpress博客比较好的外贸公司
  • 一个网站备案两个域名怎么才能注册网站
  • 西安有几家做网站metro风格网站模板
  • 网站建设维护什么意思专门开发小程序的公司
  • 做ui要上那些网站阿里云域名注册续费
  • 连云港北京网站建设友链交易平台
  • 网站后端开发软件中国建设银行纪念币预约网站
  • 长沙设计网站建设申请一个网站需要怎么做
  • 网站开发项目需求书cpa项目推广联盟
  • 怎样在华为云服务器里建设网站免费手机小说网站建设
  • 你做的网站可视区域多少整形网站开发
  • 网站规划与建设规划书做网站的外包公司可以进吗
  • 南宫网站建设页面设计软件教程
  • 电商平台正在建设中网站页面提示网站建设的话术
  • 杂志社网站建设意义个人网站 备案备注
  • 宿州企业官方网站建设融通资源开发公司
  • 网页和网站的概念大连做环评网站
  • 广州做网站多秦皇岛十大必去景点
  • 网站后台地址一般是视频制作学习
  • 网站建设方案总结评语seo优化的技巧
  • 徐州经济开发区网站黄江做网站
  • 网站logo设计制作网站建设公司发展
  • 百度上可以做中英文网站吗杭州本地网站
  • php如何给网站做支付接口做机械配件的网站