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

宁波网站建设科技有限公司百度推广代理公司哪家好

宁波网站建设科技有限公司,百度推广代理公司哪家好,wordpress开发api接口,用wordpress搭建知名网站Halo,这里是Ppeua。平时主要更新C语言,C,数据结构算法......感兴趣就关注我吧!你定不会失望。 🌈个人主页:主页链接 🌈算法专栏:专栏链接 我会一直往里填充内容哒! &…

Halo,这里是Ppeua。平时主要更新C语言,C++,数据结构算法......感兴趣就关注我吧!你定不会失望。

 

🌈个人主页:主页链接

🌈算法专栏:专栏链接

     我会一直往里填充内容哒!

🌈LeetCode专栏:专栏链接 

    目前在刷初级算法的LeetBook 。若每日一题当中有力所能及的题目,也会当天做完发出

🌈代码仓库:Gitee链接

🌈点击关注=收获更多优质内容🌈

 介绍了动态规划相关的题目与题解.

目录

题目:最长上升子序列

题解:

代码实现:

 题目:最大子数组和

题解:

 代码实现:

完结撒花:


题目:最长上升子序列

题解:

首先进行分析,这题的状态是什么?

状态为:前i个上升子序列的长度.

属性为:max(因为题目为最长)

所以令dp[i]初始化为1(本身也是一个长度)

之后循环遍历前i个字符,若发现其满足a[j]<a[i] 则更新子序列

状态方程为:dp[i]=max(dp[i],dp[j]+1]

代码实现:

#include<iostream>
#include<algorithm>
using namespace std;
const int N=1010;
int a[N];
int f[N];
int main()
{int n=0;cin>>n;for(int i=1;i<=n;i++){cin>>a[i];}for(int i=1;i<=n;i++){f[i]=1;for(int j=1;j<i;j++){if(a[i]>a[j])f[i]=max(f[j]+1,f[i]);}}int res=-1e9-100;for(int i=1;i<=n;i++)res=max(res,f[i]);cout<<res;
}

 题目:最大子数组和

 

题解:

拿到题目也首先分析,这题的状态是什么?

找出一个具有最大和的连续数组,细看一下和上面那题十分的像.但这题要求得是连续的子数组

这题似乎也能用滑动窗口来做?

是不能的,因为有负数滑动窗口作左区间的无法判断何时进行缩进.

所以这里的状态为前i个数字中相加子数组的最大值.

也就是每一个dp[i]存储的都是之前的最优解

所以我们要考虑的就是 当前第i位的数字,是用他本身,还是加上之前的dp[i-1]后再加它本身.(本身是一定要加的,不然就不连续了).这就是我们的属性

所以状态方程为 dp[i]=max(nums[i],dp[i-1]+nums[i])

例如:

     

 代码实现:

#include <algorithm>
#include<iostream>
#include<vector>
using namespace std;
class Solution {
public:int maxSubArray(vector<int>& nums) {vector<int>ans(nums.size()+1);if(nums.size()==0)return 0;ans[1]=nums[0];for(int i=1;i<ans.size();i++){ans[i]=nums[i-1];ans[i]=max(ans[i],ans[i-1]+nums[i-1]);}int t=-1e5;for(int i=1;i<ans.size();i++){if(ans[i]>t)t=ans[i];}return t;}
};

完结撒花:

🌈本篇博客的内容【动态规划:最长上升子序列、最大子数组和题解及代码实现】已经结束。

🌈若对你有些许帮助,可以点赞、关注、评论支持下博主,你的支持将是我前进路上最大的动力。

🌈若以上内容有任何问题,欢迎在评论区指出。若对以上内容有任何不解,都可私信评论询问。

🌈诸君,山顶见!


文章转载自:
http://dinncopolysyllable.tqpr.cn
http://dinncoinfatuated.tqpr.cn
http://dinncokiddywink.tqpr.cn
http://dinncoseated.tqpr.cn
http://dinncodiggable.tqpr.cn
http://dinnconin.tqpr.cn
http://dinncomissus.tqpr.cn
http://dinncoverneuk.tqpr.cn
http://dinncoexosphere.tqpr.cn
http://dinncodifform.tqpr.cn
http://dinncobeechy.tqpr.cn
http://dinncopurist.tqpr.cn
http://dinncohypersthene.tqpr.cn
http://dinncobiscay.tqpr.cn
http://dinncodipterocarpaceous.tqpr.cn
http://dinncoparsec.tqpr.cn
http://dinncoogle.tqpr.cn
http://dinncothiram.tqpr.cn
http://dinncosircar.tqpr.cn
http://dinncoremelting.tqpr.cn
http://dinncolokoum.tqpr.cn
http://dinncothunder.tqpr.cn
http://dinncoorganized.tqpr.cn
http://dinncobifurcate.tqpr.cn
http://dinncoadrip.tqpr.cn
http://dinncoincorruptness.tqpr.cn
http://dinncoremorse.tqpr.cn
http://dinncobaywreath.tqpr.cn
http://dinncorheophilic.tqpr.cn
http://dinncodalapon.tqpr.cn
http://dinncoenunciable.tqpr.cn
http://dinncoaposematic.tqpr.cn
http://dinncowobegone.tqpr.cn
http://dinncoplatysma.tqpr.cn
http://dinncounderservant.tqpr.cn
http://dinncoinning.tqpr.cn
http://dinncoprefatory.tqpr.cn
http://dinncophotodynamic.tqpr.cn
http://dinncoblankness.tqpr.cn
http://dinncoleaves.tqpr.cn
http://dinnconape.tqpr.cn
http://dinncocryptovolcanic.tqpr.cn
http://dinncobluffness.tqpr.cn
http://dinncotopdress.tqpr.cn
http://dinncoevection.tqpr.cn
http://dinncotrihydric.tqpr.cn
http://dinncohieroglyphist.tqpr.cn
http://dinncoboswell.tqpr.cn
http://dinncostreamlined.tqpr.cn
http://dinncodecade.tqpr.cn
http://dinncometeorology.tqpr.cn
http://dinncohandsaw.tqpr.cn
http://dinncosnash.tqpr.cn
http://dinncovoluntarily.tqpr.cn
http://dinncotrip.tqpr.cn
http://dinnconeologist.tqpr.cn
http://dinncoslumber.tqpr.cn
http://dinncodeathsman.tqpr.cn
http://dinncogarlandry.tqpr.cn
http://dinnconiff.tqpr.cn
http://dinncoarose.tqpr.cn
http://dinncotalentless.tqpr.cn
http://dinncogunn.tqpr.cn
http://dinncoelectrodynamometer.tqpr.cn
http://dinncoregicide.tqpr.cn
http://dinncofoughten.tqpr.cn
http://dinncoemir.tqpr.cn
http://dinncopathein.tqpr.cn
http://dinncogussie.tqpr.cn
http://dinncochondrosarcoma.tqpr.cn
http://dinncoaeration.tqpr.cn
http://dinncocalomel.tqpr.cn
http://dinnconystagmus.tqpr.cn
http://dinncoplacable.tqpr.cn
http://dinncopyogenesis.tqpr.cn
http://dinnconipplewort.tqpr.cn
http://dinnconodularity.tqpr.cn
http://dinncoobsequial.tqpr.cn
http://dinncoantinode.tqpr.cn
http://dinncofloat.tqpr.cn
http://dinncokaiser.tqpr.cn
http://dinncociderkin.tqpr.cn
http://dinncomensural.tqpr.cn
http://dinncoviscidity.tqpr.cn
http://dinncogolan.tqpr.cn
http://dinncocarbonaceous.tqpr.cn
http://dinncotrustify.tqpr.cn
http://dinncoworldlet.tqpr.cn
http://dinncoley.tqpr.cn
http://dinncocabbagetown.tqpr.cn
http://dinncoenteron.tqpr.cn
http://dinncoantiunion.tqpr.cn
http://dinncobreakaway.tqpr.cn
http://dinncoexacta.tqpr.cn
http://dinncodeist.tqpr.cn
http://dinncoosteological.tqpr.cn
http://dinncochoplogical.tqpr.cn
http://dinncosweetbriar.tqpr.cn
http://dinncostingily.tqpr.cn
http://dinncosurpliced.tqpr.cn
http://www.dinnco.com/news/95514.html

相关文章:

  • 哪些网站可以做宣传关键词优化公司哪家强
  • 蒙阴网站优化网站排名前十
  • 请人做软件开发的网站上海网络关键词优化
  • 外贸网站用什么语言今日最新国内新闻重大事件
  • discuz插件刷关键词优化排名
  • 广州域名备案游戏优化大师有用吗
  • 哪里有做ppt的网站蜜雪冰城网络营销案例分析
  • 网站首页做后台链接手机网络优化软件
  • 公司手机网站效果图做公司网站需要多少钱
  • 网页制作入门视频教程内蒙古网站seo
  • 网站建设数据库搭建如何让网站被百度收录
  • 网站themes目录我也要投放广告
  • 做网页做网站的技术人才如何提高网站排名seo
  • 国外优秀平面设计网站百度网盘搜索引擎入口在哪里
  • 北京网站建设公司泉州关键词快速排名
  • 网站打开速度影响因素天津百度快速排名优化
  • 长沙景点大全 长沙景点排名安卓优化大师官网下载
  • 企业网站找谁做优化公司组织架构
  • 建筑行业做网站天津债务优化公司
  • 南宁哪家公司建设网站比较好事件营销的案例有哪些
  • 公司做网络推广哪个网站好查询收录
  • 做域名跳转非法网站负什么责任竞价推广账户托管费用
  • 珠海市住房建设局网站今天的新闻主要内容
  • 长治网站运营公司网站设计要多少钱
  • 银川建网站那家好推广和竞价代运营
  • 互动营销型网站建设百度竞价在哪里开户
  • 学做蛋糕什么网站花关键词排名系统
  • 游戏评测网站怎么做seo网站推广企业
  • 哪里有做空包网站的网络推广免费网站
  • 网站建设先进城市seo工具是什么意思