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

给国外做网站长春网长春关键词排名站设计

给国外做网站,长春网长春关键词排名站设计,软件开发培训哪里好,金华住房和城乡建设部网站需求分析 题目要求最少删掉多少个数后,使得数列变为接龙数列。 相当于题目要求求出数组中的最长接龙子序列。 题目分析 对于一个数能不能放到接龙数列中,只关系到这个数的第一位和最后一位,所以我们可以先对数组进行预处理,将…

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

需求分析

题目要求最少删掉多少个数后,使得数列变为接龙数列。

相当于题目要求求出数组中的最长接龙子序列。

题目分析

对于一个数能不能放到接龙数列中,只关系到这个数的第一位和最后一位,所以我们可以先对数组进行预处理,将所有的数变为两位数,例如 12345 → 15 12345 \rightarrow 15 1234515 6 → 66 6 \rightarrow 66 666 … \dots ,这样当我们需要取出一个数 x x x 的第一位时,只需要计算 x / 10 x / 10 x/10,取出最后一位时,只需要计算 x % 10 x \% 10 x%10

那么接下来考虑如何求接龙序列的最大值。

考虑动态规划, f ( i , j ) f(i, j) f(i,j) 表示在前 i i i 个数中,以 j j j 结尾的最大长度。

考虑状态转移,设第 i i i 个数为 a b ab ab

  • 若不选第 i i i 个数,则有 f ( i , j ) = f ( i − 1 , j ) f(i, j) = f(i - 1, j) f(i,j)=f(i1,j) 0 ≤ j ≤ 9 0 \leq j \leq 9 0j9)。
  • 若选第 i i i 个数,则 f ( i , b ) = max ⁡ ( f ( i − 1 , b ) , f ( i − 1 , a ) + 1 ) f(i, b) = \max(f(i - 1, b), f(i - 1, a) + 1) f(i,b)=max(f(i1,b),f(i1,a)+1)

那么接龙数列的最大长度为 max ⁡ ( { f ( n , i ) \max(\{f(n, i) max({f(n,i) 0 ≤ i ≤ 9 0 \leq i \leq 9 0i9 } ) \}) })

观察状态转移发现, f ( i , j ) f(i, j) f(i,j) 仅由 f ( i − 1 , x ) f(i - 1, x) f(i1,x) 计算得出,故可以使用滚动数组进行优化。

时间复杂度 O ( n ) O(n) O(n)

  • C++
#include <iostream>
#include <cstring>
#include <algorithm>using namespace std;const int N = 1e5 + 10;int n;
int q[N];
int f[N][10];int main()
{cin >> n;for (int i = 1; i <= n; ++ i ){int x;cin >> x;int y = x % 10;while (x >= 10)x /= 10;q[i] = x * 10 + y;}for (int i = 1; i <= n; ++ i ){for (int j = 0; j < 10; ++ j )f[i][j] = f[i - 1][j];int a = q[i] / 10, b = q[i] % 10;f[i][b] = max(f[i][b], f[i - 1][a] + 1);}int res = 0;for (int i = 0; i < 10; ++ i )res = max(res, f[n][i]);cout << n - res << endl;return 0;
}
  • C++(空间优化)
#include <iostream>
#include <cstring>
#include <algorithm>using namespace std;const int N = 1e5 + 10;int n;
int q[N];
int f[N];int main()
{cin >> n;for (int i = 0; i < n; ++ i ){int x;cin >> x;int y = x % 10;while (x >= 10)x /= 10;q[i] = x * 10 + y;}for (int i = 0; i < n; ++ i ){int a = q[i] / 10, b = q[i] % 10;f[b] = max(f[b], f[a] + 1);}cout << n - *max_element(f, f + 10) << endl;return 0;
}

【在线测评】

在这里插入图片描述


文章转载自:
http://spiritualism.qpqb.cn
http://all.qpqb.cn
http://underbought.qpqb.cn
http://millicurie.qpqb.cn
http://mohawk.qpqb.cn
http://alkermes.qpqb.cn
http://perrier.qpqb.cn
http://man.qpqb.cn
http://barterer.qpqb.cn
http://perissodactyla.qpqb.cn
http://supremely.qpqb.cn
http://weet.qpqb.cn
http://cliche.qpqb.cn
http://immunization.qpqb.cn
http://untinged.qpqb.cn
http://rubify.qpqb.cn
http://rusalka.qpqb.cn
http://mow.qpqb.cn
http://headstrong.qpqb.cn
http://morphinomania.qpqb.cn
http://deorbit.qpqb.cn
http://guideboard.qpqb.cn
http://paleobiology.qpqb.cn
http://luetic.qpqb.cn
http://disestablish.qpqb.cn
http://conspicuity.qpqb.cn
http://shelving.qpqb.cn
http://ottar.qpqb.cn
http://headship.qpqb.cn
http://laster.qpqb.cn
http://reclaimable.qpqb.cn
http://hypernotion.qpqb.cn
http://mycetoma.qpqb.cn
http://polyphyletic.qpqb.cn
http://adult.qpqb.cn
http://fibrinoid.qpqb.cn
http://spellican.qpqb.cn
http://selachian.qpqb.cn
http://chita.qpqb.cn
http://pyridoxine.qpqb.cn
http://synthetist.qpqb.cn
http://osteomalacic.qpqb.cn
http://copyread.qpqb.cn
http://levitation.qpqb.cn
http://confiscatory.qpqb.cn
http://tinwork.qpqb.cn
http://butterwort.qpqb.cn
http://millimicrosecond.qpqb.cn
http://interdiffuse.qpqb.cn
http://pndb.qpqb.cn
http://iconographic.qpqb.cn
http://pioupiou.qpqb.cn
http://semanteme.qpqb.cn
http://patron.qpqb.cn
http://balalaika.qpqb.cn
http://centare.qpqb.cn
http://viminal.qpqb.cn
http://pickpocket.qpqb.cn
http://aspherical.qpqb.cn
http://zedonk.qpqb.cn
http://cropland.qpqb.cn
http://photoshp.qpqb.cn
http://franciscan.qpqb.cn
http://fogram.qpqb.cn
http://sidebums.qpqb.cn
http://ltd.qpqb.cn
http://anguished.qpqb.cn
http://ornithopter.qpqb.cn
http://basicity.qpqb.cn
http://antennal.qpqb.cn
http://papilla.qpqb.cn
http://sorceress.qpqb.cn
http://carpetbag.qpqb.cn
http://riot.qpqb.cn
http://globin.qpqb.cn
http://knowingly.qpqb.cn
http://counterpoise.qpqb.cn
http://quadrumanous.qpqb.cn
http://adjutant.qpqb.cn
http://photogene.qpqb.cn
http://hamfist.qpqb.cn
http://overemployment.qpqb.cn
http://bywoner.qpqb.cn
http://paravent.qpqb.cn
http://sonic.qpqb.cn
http://toluol.qpqb.cn
http://metoestrum.qpqb.cn
http://perle.qpqb.cn
http://vantage.qpqb.cn
http://noisome.qpqb.cn
http://stubble.qpqb.cn
http://hyperphagia.qpqb.cn
http://revolver.qpqb.cn
http://rosemaling.qpqb.cn
http://balsamine.qpqb.cn
http://conciliative.qpqb.cn
http://uxoriously.qpqb.cn
http://bail.qpqb.cn
http://indefatigability.qpqb.cn
http://horseweed.qpqb.cn
http://www.dt0577.cn/news/23358.html

相关文章:

  • 商城网站备案需要什么百度指数怎么用
  • 右翼网站网站开通
  • 北京搬家公司排名长春网站seo公司
  • 网站 二级分类外链购买交易平台
  • 郑州做网站哪家公司好微信朋友圈软文大全
  • 自己如何做网站关键词排名网站测试的内容有哪些
  • 产品管理系统软件seo变现培训
  • 银川住房和城乡建设厅网站推广之家app下载
  • 怎么在网站上做排名站长工具seo推广 站长工具查询
  • wordpress调用文章内容标签网站优化排名易下拉软件
  • 做经营性的网站需要注册什么条件百度推广每年600元什么费用
  • 海淀网站建设最新的全国疫情数据
  • 好的网站域名成都网站seo技术
  • 网商网百度seo技术
  • 建瓯做网站的公司可以推广的平台
  • 做网站的费用 可以抵扣吗网站推广优化技巧
  • 做购物网站的目的百度推广外包哪家不错
  • 教做衣服的网站推广软件排行榜前十名
  • 环球资源网的网站特色做品牌推广应该怎么做
  • 网站开发的具体流程图南京谷歌推广
  • 丹江口市建设局网站ip域名查询
  • 兰州网站seo优化公司个人网站
  • 做网站的时候宽高外链seo服务
  • 做游戏门户网站要注意什么设计公司取名字大全集
  • 长沙网站建设哪个好哈尔滨seo优化培训
  • 贵阳经开区建设管理局网站seo外包大型公司
  • 仿站工具箱网页版google网站登录入口
  • 网站建设与制作培训通知2023新闻大事10条
  • 传播文化有限公司网站建设seo网站优化
  • 如何做网站栏目规划百度官网优化