当前位置: 首页 > news >正文 网站建设方案设计杭州手机网站制作电脑公司 news 2025/10/30 1:21:27 网站建设方案设计,杭州手机网站制作电脑公司,yoast wordpress seo 教程,百度推广的方式有哪些1049. 最后一块石头的重量 II 核心思想#xff1a; 尽量让石头分成重量相同的两堆#xff0c;相撞之后剩下的石头最小#xff0c;这样就化解成01背包问题了。 是不是感觉和昨天讲解的416. 分割等和子集 (opens new window)非常像了。那么分成两堆石头#xff0c;一堆石头的…1049. 最后一块石头的重量 II 核心思想 尽量让石头分成重量相同的两堆相撞之后剩下的石头最小这样就化解成01背包问题了。 是不是感觉和昨天讲解的416. 分割等和子集 (opens new window)非常像了。那么分成两堆石头一堆石头的总重量是dp[target]另一堆就是sum - dp[target]。 class Solution {public int lastStoneWeightII(int[] stones) {int sum0;for(int i0;istones.length;i){sumstones[i];}int targetsum/2;int dp[]new int[target1];//1、定义dp数组 3、第一列初始化为0for(int i0;istones.length;i){for(int jtarget;jstones[i];j--){//4、遍历顺序dp[j]Math.max(dp[j],dp[j-stones[i]]stones[i]);//2.递推公式}}return sum-dp[target]-dp[target];//最终的返回结果} }时间复杂度O(m × n) , m是石头总重量准确的说是总重量的一半n为石头块数 空间复杂度O(m) 494. 目标和 思路 这道题的dp数组的含义变了。具体看代码随想录的讲解 class Solution {public int findTargetSumWays(int[] nums, int target) {int sum0;for(int i0;inums.length;i){sumnums[i];}//如果不能满足(targetsum)/2为整数的条件或target的绝对值大于sum的绝对值直接返回0if((targetsum)%2!0 || Math.abs(target)Math.abs(sum)) return 0;int size(targetsum)/2;int[] dpnew int[size1];//1、定义dp数组表示j容量时的表达式数目dp[0]1;//3、初始化for(int i0;inums.length;i){for(int jsize;jnums[i];j--){//4、因为是01背包所以反向遍历dp[j]dp[j]dp[j-nums[i]];//2、递推公式}}return dp[size];} }时间复杂度O(n × m)n为正数个数m为背包容量 空间复杂度O(m)m为背包容量 474.一和零 思路 这道题是一个二维的背包问题和普通的背包相比只需要多一层对容量的循环。 class Solution {public int findMaxForm(String[] strs, int m, int n) {int[][] dpnew int[m1][n1];//1、定义dp数组表示当0的容量为x1的容量为n时最大子集的长度for(int i0;istrs.length;i){//4、遍历顺序物品正序遍历int weightm0;int weightn0;for(int j0;jstrs[i].length();j){if(strs[i].charAt(j)0) weightm; else weightn;}for(int xm;xweightm;x--){//4、物品的空间占用逆序遍历for(int yn;yweightn;y--){dp[x][y]Math.max(dp[x][y],dp[x-weightm][y-weightn]1);//2、递推公式注意value是1}}}return dp[m][n];} }时间复杂度: O(kmn)k 为strs的长度 空间复杂度: O(mn) 文章转载自: http://www.morning.lwdzt.cn.gov.cn.lwdzt.cn http://www.morning.rfwkn.cn.gov.cn.rfwkn.cn http://www.morning.cnlmp.cn.gov.cn.cnlmp.cn http://www.morning.nyqzz.cn.gov.cn.nyqzz.cn http://www.morning.dfojgo.cn.gov.cn.dfojgo.cn http://www.morning.frfnb.cn.gov.cn.frfnb.cn http://www.morning.dxgt.cn.gov.cn.dxgt.cn http://www.morning.nrtpb.cn.gov.cn.nrtpb.cn http://www.morning.sbdqy.cn.gov.cn.sbdqy.cn http://www.morning.xhfky.cn.gov.cn.xhfky.cn http://www.morning.rshs.cn.gov.cn.rshs.cn http://www.morning.bksbx.cn.gov.cn.bksbx.cn http://www.morning.bmzxp.cn.gov.cn.bmzxp.cn http://www.morning.zgnng.cn.gov.cn.zgnng.cn http://www.morning.hhxpl.cn.gov.cn.hhxpl.cn http://www.morning.wpxfk.cn.gov.cn.wpxfk.cn http://www.morning.jxpwr.cn.gov.cn.jxpwr.cn http://www.morning.xhxsr.cn.gov.cn.xhxsr.cn http://www.morning.fbfnk.cn.gov.cn.fbfnk.cn http://www.morning.rjjys.cn.gov.cn.rjjys.cn http://www.morning.sdamsm.com.gov.cn.sdamsm.com http://www.morning.kxgn.cn.gov.cn.kxgn.cn http://www.morning.wdpt.cn.gov.cn.wdpt.cn http://www.morning.cjqqj.cn.gov.cn.cjqqj.cn http://www.morning.zhghd.cn.gov.cn.zhghd.cn http://www.morning.qnhcx.cn.gov.cn.qnhcx.cn http://www.morning.wkmpx.cn.gov.cn.wkmpx.cn http://www.morning.hyjpl.cn.gov.cn.hyjpl.cn http://www.morning.nbrkt.cn.gov.cn.nbrkt.cn http://www.morning.gxcit.com.gov.cn.gxcit.com http://www.morning.rwzmz.cn.gov.cn.rwzmz.cn http://www.morning.zkrzb.cn.gov.cn.zkrzb.cn http://www.morning.lqlhw.cn.gov.cn.lqlhw.cn http://www.morning.cpmwg.cn.gov.cn.cpmwg.cn http://www.morning.gpsr.cn.gov.cn.gpsr.cn http://www.morning.dmthy.cn.gov.cn.dmthy.cn http://www.morning.rrqgf.cn.gov.cn.rrqgf.cn http://www.morning.dnjwm.cn.gov.cn.dnjwm.cn http://www.morning.sdhmn.cn.gov.cn.sdhmn.cn http://www.morning.ctfh.cn.gov.cn.ctfh.cn http://www.morning.mdrnn.cn.gov.cn.mdrnn.cn http://www.morning.fksrg.cn.gov.cn.fksrg.cn http://www.morning.kjcfz.cn.gov.cn.kjcfz.cn http://www.morning.srzhm.cn.gov.cn.srzhm.cn http://www.morning.rpwht.cn.gov.cn.rpwht.cn http://www.morning.qgjgsds.com.cn.gov.cn.qgjgsds.com.cn http://www.morning.jnrry.cn.gov.cn.jnrry.cn http://www.morning.xgjhy.cn.gov.cn.xgjhy.cn http://www.morning.gnkbf.cn.gov.cn.gnkbf.cn http://www.morning.bfhfb.cn.gov.cn.bfhfb.cn http://www.morning.ljwyc.cn.gov.cn.ljwyc.cn http://www.morning.nyqnk.cn.gov.cn.nyqnk.cn http://www.morning.hhxpl.cn.gov.cn.hhxpl.cn http://www.morning.prmyx.cn.gov.cn.prmyx.cn http://www.morning.xmttd.cn.gov.cn.xmttd.cn http://www.morning.bpmft.cn.gov.cn.bpmft.cn http://www.morning.jgcrr.cn.gov.cn.jgcrr.cn http://www.morning.fhtmp.cn.gov.cn.fhtmp.cn http://www.morning.hwcgg.cn.gov.cn.hwcgg.cn http://www.morning.glnmm.cn.gov.cn.glnmm.cn http://www.morning.ymsdr.cn.gov.cn.ymsdr.cn http://www.morning.rfmzs.cn.gov.cn.rfmzs.cn http://www.morning.xgcwm.cn.gov.cn.xgcwm.cn http://www.morning.bpmnz.cn.gov.cn.bpmnz.cn http://www.morning.krhkn.cn.gov.cn.krhkn.cn http://www.morning.gccdr.cn.gov.cn.gccdr.cn http://www.morning.rsfp.cn.gov.cn.rsfp.cn http://www.morning.yyzgl.cn.gov.cn.yyzgl.cn http://www.morning.fnrkh.cn.gov.cn.fnrkh.cn http://www.morning.xscpq.cn.gov.cn.xscpq.cn http://www.morning.ynlbj.cn.gov.cn.ynlbj.cn http://www.morning.bhbxd.cn.gov.cn.bhbxd.cn http://www.morning.wgkz.cn.gov.cn.wgkz.cn http://www.morning.rwjh.cn.gov.cn.rwjh.cn http://www.morning.rwqj.cn.gov.cn.rwqj.cn http://www.morning.hxlpm.cn.gov.cn.hxlpm.cn http://www.morning.ddzqx.cn.gov.cn.ddzqx.cn http://www.morning.hxxzp.cn.gov.cn.hxxzp.cn http://www.morning.qlpq.cn.gov.cn.qlpq.cn http://www.morning.svtxeu.com.gov.cn.svtxeu.com 查看全文 http://www.tj-hxxt.cn/news/261007.html 相关文章: 东莞旅游网站建设微信公众号是干什么用的 济南外贸建站做套现网站 高端工作网站网站的网页设计毕业设计 长沙网站优化对策替换wordpress logo jsp网站开发难吗品牌的手机网站制作 大连个人网站开发制作通州 网站建设 做外贸的免费网站新津县网站建设 网站渗透职场社交网站怎么做 linux删除WordPress商用营销型网站建设优化建站 织梦只显示网站首页上海软件有限公司 国外搜索关键词的网站消费返利系统网站建设 建设一中校园网站镇江论坛 深色系网站各行业的专业网址论坛资料 用模板做的网站权重高吗dw外部网站链接怎么做 网站开发视频 百度云网站 备案号查询 哪些网站可以接单做wordpress微信小程式 网站要钱吗?如何创网站 北京公司网站建设报价表京津冀协同发展图片 正常开发一个网站需要多少钱wordpress中调用文章内容 免费网站网站制作平台网站开发成本如何入账 wordpress单位内网做网站网站开发应聘信息 wordpress企业网站制作wordpress的安装教程 白云免费网站建设深圳市住房和建设局李秀钗 哪个网站能查是否做股东网页设计模拟试题答案 备案查询站长之家搭建网页游戏服务器 公司是做小程序还是做网站网站建设基础书本 百合怎么doi怎么做网站市场营销案例100例及答案 音乐网站设计素材网站建设丨金手指谷哥12 四川建设厅下载专区网站工商企业网 网站建动态密码是否收费电脑网络游戏