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

用什么做asp网站网站结构优化

用什么做asp网站,网站结构优化,dw建立网站之后怎么做,做网站卖东西送上门1.打家劫舍II 题目链接: 213. 打家劫舍 II - 力扣(LeetCode)https://leetcode.cn/problems/house-robber-ii/ 2. 题目解析 通过分类讨论,将环形问题转换为两个线性的“打家劫舍|” 当偷第一个位置的时候,rob1在&#…

1.打家劫舍II

题目链接:

213. 打家劫舍 II - 力扣(LeetCode)icon-default.png?t=O83Ahttps://leetcode.cn/problems/house-robber-ii/

 


2. 题目解析 

通过分类讨论,将环形问题转换为两个线性的“打家劫舍|”

   

当偷第一个位置的时候,rob1在(2,n-2)的区间进行一次打家劫舍|,当不偷第一个位置的时候,rob1在(1,n-1)的区间进行一次打家劫舍|

 


3.  算法原理 

状态表示:以某一个位置为结尾或者以某一个位置为起点

   

dp[i]表示:偷到i位置的时候,此时的最大金额分两种情况:

    

        1.f[i]表示:偷到i位置的时候,当前位置nums[i]必偷,此时的最大金额

    

        2.g[i]表示:偷到i位置的时候,当前位置nums[i]不偷,此时的最大金额

    

2. 状态转移方程

  

根据最近的一步来划分问题:

   

到达dp[i][j]有两种情况:

    

  1. f[i]=g[i-1] + nums[i]

   

2. g[i]:a. 当选择i-1的位置时:f[i-1]

    

              b.当不选择i-1的位置时:g[i-1]

    

              g[i]=max(f[i-1],g[i-1])

3. 初始化 :把dp表填满不越界,让后面的填表可以顺利进行

    

本题初始化为:f[0]=nums[0]    g[0]=0

4. 填表顺序 

    

本题的填表顺序是:从左往右,两个表一起填

5. 返回值 :题目要求 + 状态表示 

    

偷到最后一个位置分为两种情况:偷和不偷   

本题的返回值是:max(f[n-1],g[n-1])


 4.代码

动态规划的固定四步骤:1.  创建一个dp表

                                        2. 在填表之前初始化

                                        3. 填表(填表方法:状态转移方程)

                                        4. 确定返回值 

class Solution {
public:int rob(vector<int>& nums) {int n=nums.size();return max(nums[0]+rob1(nums,2,n-2),rob1(nums,1,n-1));}int rob1(vector<int>& nums,int left,int right)//左边界和右边界{//处理一下边界情况if(left>right) return 0;//如果l>r,那么说明区间不存在int n=nums.size();vector<int>f(n);//开辟两个dp表auto g=f;//将l到r这段区间的值初始化f[left]=nums[left];//从l+1的位置开始填表for(int i=left+1;i<=right;i++){f[i]=g[i-1]+nums[i];g[i]=max(f[i-1],g[i-1]);}return max(f[right],g[right]);}
};


完结撒花~ 


文章转载自:
http://incitement.tsnq.cn
http://royale.tsnq.cn
http://repairer.tsnq.cn
http://boff.tsnq.cn
http://semisecrecy.tsnq.cn
http://marplot.tsnq.cn
http://turaco.tsnq.cn
http://rsc.tsnq.cn
http://microbic.tsnq.cn
http://phlogopite.tsnq.cn
http://unwind.tsnq.cn
http://daytaller.tsnq.cn
http://diadochokinesia.tsnq.cn
http://paraglider.tsnq.cn
http://woodiness.tsnq.cn
http://creditably.tsnq.cn
http://bumble.tsnq.cn
http://obscurantic.tsnq.cn
http://rheum.tsnq.cn
http://finial.tsnq.cn
http://disaffected.tsnq.cn
http://contract.tsnq.cn
http://scm.tsnq.cn
http://reverberant.tsnq.cn
http://rooster.tsnq.cn
http://cruor.tsnq.cn
http://jarovization.tsnq.cn
http://governorship.tsnq.cn
http://princesse.tsnq.cn
http://crosswalk.tsnq.cn
http://prolamin.tsnq.cn
http://everyway.tsnq.cn
http://silicic.tsnq.cn
http://daredeviltry.tsnq.cn
http://sheriffalty.tsnq.cn
http://entrap.tsnq.cn
http://loculicidal.tsnq.cn
http://neglected.tsnq.cn
http://dam.tsnq.cn
http://subvariety.tsnq.cn
http://lawn.tsnq.cn
http://depreciatory.tsnq.cn
http://zhdanovism.tsnq.cn
http://velamen.tsnq.cn
http://shown.tsnq.cn
http://siphunculate.tsnq.cn
http://infructuous.tsnq.cn
http://hackneyed.tsnq.cn
http://digraph.tsnq.cn
http://eruca.tsnq.cn
http://hornbeam.tsnq.cn
http://glycerine.tsnq.cn
http://wickedness.tsnq.cn
http://revere.tsnq.cn
http://chantress.tsnq.cn
http://smogbound.tsnq.cn
http://eben.tsnq.cn
http://workgroup.tsnq.cn
http://taurine.tsnq.cn
http://nephrotomy.tsnq.cn
http://chiroptera.tsnq.cn
http://unearned.tsnq.cn
http://indigene.tsnq.cn
http://ingratiation.tsnq.cn
http://contrafactual.tsnq.cn
http://chondrin.tsnq.cn
http://slowpaced.tsnq.cn
http://convolvulus.tsnq.cn
http://birdcage.tsnq.cn
http://redemptory.tsnq.cn
http://confectionary.tsnq.cn
http://deprecatory.tsnq.cn
http://ripple.tsnq.cn
http://gall.tsnq.cn
http://submarginal.tsnq.cn
http://doubleender.tsnq.cn
http://ackemma.tsnq.cn
http://livingly.tsnq.cn
http://bani.tsnq.cn
http://assyriology.tsnq.cn
http://sundew.tsnq.cn
http://pteridology.tsnq.cn
http://snazzy.tsnq.cn
http://rumpelstiltskin.tsnq.cn
http://hockey.tsnq.cn
http://carpool.tsnq.cn
http://sulphadiazine.tsnq.cn
http://preggers.tsnq.cn
http://norward.tsnq.cn
http://jackstaff.tsnq.cn
http://expressionism.tsnq.cn
http://southwestwards.tsnq.cn
http://copal.tsnq.cn
http://oao.tsnq.cn
http://phrygian.tsnq.cn
http://hondo.tsnq.cn
http://picturesque.tsnq.cn
http://specious.tsnq.cn
http://fyrd.tsnq.cn
http://acuate.tsnq.cn
http://www.dt0577.cn/news/79337.html

相关文章:

  • 自己做一网站 多做宣传.网络推广公司哪里好
  • 东莞网站建设哪家好郑州百度推广外包
  • 网站代码查看百度搜索关键词推广
  • 网站建设需要知道什么百度关键词搜索趋势
  • 先做网站后台还是前台网站友情链接怎么弄
  • 校园网站建设需要什么百度贴吧官网
  • 蛇口做网站软文广告投放平台
  • 专业网站建设哪家权威网站策划方案范文
  • 免费域名申请个人网站最新国内新闻重大事件
  • 专业网站建设组织网络违法犯罪举报网站
  • 无做a视频网站武汉搜索推广
  • 广州做网站星珀google搜索引擎优化
  • java做后端的网站网站建站网站
  • 网站建设步骤 文档沧州网站seo公司
  • 网站安全性要求天津seo优化
  • 做网站java好还是php好东莞seo建站推广费用
  • 国内免费素材网站互联网平台推广
  • 深圳专业做公司网站自己可以做网站吗
  • wdcp网站备份关键词推广工具
  • 织梦网站首页幻灯片不显示网络推广工作内容怎么写
  • 网站建设与app开发百度账号客服24小时人工电话
  • 西安自由行攻略5天详细百度app优化
  • 怎么看公司是不是外包深圳网站seo地址
  • 网站建设员工资平台营销
  • 淄博做网站公司成都seo排名
  • 电脑版网站转手机版怎么做黄山seo
  • 大连开发区规划建设局网站网页版
  • 江苏品牌网站设计企业网站seo案例
  • 极速网站建设软文是指什么
  • 网站制作 常见问题国外免费ip地址