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

做网站背景图片要多大关键字c语言

做网站背景图片要多大,关键字c语言,网站制作方案的重要性,网站选择城市怎么做文章目录 1. 汉诺塔问题题干:算法原理:代码: 2. 合并两个有序链表题干:算法原理:代码: 3. 反转链表题干:算法原理:代码: 4. 最大子数组和题干:算法原理&#…

文章目录

  • 1. 汉诺塔问题
    • 题干:
    • 算法原理:
    • 代码:
  • 2. 合并两个有序链表
    • 题干:
    • 算法原理:
    • 代码:
  • 3. 反转链表
    • 题干:
    • 算法原理:
    • 代码:
  • 4. 最大子数组和
    • 题干:
    • 算法原理:
      • 1. 状态表示:
      • 2. 状态转移方程
      • 3. 初始化
      • 4. 填表顺序
      • 5. 返回值
    • 代码:
  • 5. 环形子数组的最大和
    • 题干:
    • 算法原理:
      • 1. 状态表示:
      • 2. 状态转移方程
      • 3. 初始化
      • 4. 填表顺序
      • 5. 返回值
    • 代码:

1. 汉诺塔问题

在这里插入图片描述
原题链接


题干:

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


算法原理:

利用递归算法

将x柱子上的一堆盘子,借助 y柱子,转移到z 柱子上面

递归函数流程:

  1. 当前问题规模为 n=1 时,直接将 A 中的最上面盘子挪到 C 中并返回
  2. 递归将 A 中最上面的 n-1 个盘子挪到 B 中
  3. 将 A 中最上面的⼀个盘子挪到 C 中
  4. 将 B 中上面 n-1 个盘子挪到 C 中

代码:

class Solution {public void hanota(List<Integer> a, List<Integer> b, List<Integer> c) {dfs(a, b, c, a.size());}public void dfs(List<Integer> a, List<Integer> b, List<Integer> c, int n) {if(n == 1) {c.add(a.remove(a.size() - 1));return;}dfs(a, c, b, n - 1);c.add(a.remove(a.size() - 1));dfs(b, a, c, n - 1);}
}

2. 合并两个有序链表

在这里插入图片描述

原题链接


题干:

升序 链表
新链表是通过拼接给定的两个链表的所有节点组成的
在这里插入图片描述


算法原理:

  1. 重复子问题(函数头的设计)
    合并两个有序链表

  2. 只关心一个子问题咋做什么(函数体的设计)
    选择两个头结点中较小的结点作为最终合并后的头结点,然后将剩下的链表交给递归函数去处理

  3. 递归的出口
    谁为空返回另一个


代码:

class Solution {public ListNode mergeTwoLists(ListNode l1, ListNode l2) {if(l1 == null) {return l2;}if(l2 == null) {return l1;}if(l1.val <= l2.val) {l1.next = mergeTwoLists(l1.next, l2);return l1;}else {l2.next = mergeTwoLists(l1, l2.next);return l2;}}
}

3. 反转链表

在这里插入图片描述
原题链接


题干:

单链表的头节点 head ,反转链表,并返回反转后的链表
在这里插入图片描述


算法原理:

利用递归

  1. 从宏观角度
    1)让当前节点后面的链表先逆序,并且把头结点返回
    2)让当前节点添加到逆置后的链表的后面
  2. 将链表看成一棵树
    仅需做一次 dfs 即可
    后序遍历
    在这里插入图片描述

代码:

class Solution {public ListNode reverseList(ListNode head) {if(head == null || head.next == null) {return head;}ListNode newheader = reverseList(head.next);head.next.next = head;head.next = null;return newheader;}
}

4. 最大子数组和

在这里插入图片描述
原题链接


题干:

一个整数数组 nums
找出一个具有最大和的连续子数组


算法原理:

1. 状态表示:

dp[i] 表示:以 i 位置为结尾的所有子数组中的最大和
在这里插入图片描述

2. 状态转移方程

在这里插入图片描述
dp[i] = max(nums[i], dp[i - 1] + nums[i])

3. 初始化

  1. 辅助结点里面的值要「保证后续填表是正确的」
  2. 「下标的映射关系」

在这里插入图片描述

4. 填表顺序

从左往右

5. 返回值

整个dp表的最大值


代码:

class Solution {public int maxSubArray(int[] nums) {int n = nums.length;int[] dp = new int[n + 1];int ret = Integer.MIN_VALUE;for(int i = 1; i <= n; i++) {dp[i] = Math.max(nums[i - 1], dp[i - 1] + nums[i - 1]);ret = Math.max(ret, dp[i]);} return ret;}
}

5. 环形子数组的最大和

在这里插入图片描述
原题链接


题干:

长度为 n 的环形整数数组 nums
返回 nums 的非空 子数组 的最大可能和


算法原理:

在这里插入图片描述

1. 状态表示:

在这里插入图片描述

2. 状态转移方程

在这里插入图片描述

f[i] = max(nums[i], f[i - 1] + nums[i])
在这里插入图片描述

g[i] = min(nums[i], g[i - 1] + nums[i])

3. 初始化

  1. 辅助结点里面的值要「保证后续填表是正确的」
  2. 「下标的映射关系」
  3. 在这里插入图片描述

4. 填表顺序

从左往右

5. 返回值

  1. 先找到 f 表里面的最大值 -> fmax
  2. 找到 g 表里面的最小值 -> gmin
  3. 统计所有元素的和 -> sum
  4. 返回 sum == gmin ? fmax : max(fmax, sum - gmin)

代码:

class Solution {public int maxSubarraySumCircular(int[] nums) {int n = nums.length;int[] f = new int[n + 1];int[] g = new int[n + 1];int sum = 0;int fmax = Integer.MIN_VALUE;int gmin = Integer.MAX_VALUE;for(int i = 1; i <= n; i++) {int x = nums[i - 1];f[i] = Math.max(x, x + f[i - 1]);fmax = Math.max(fmax, f[i]);g[i] = Math.min(x, x + g[i - 1]);gmin = Math.min(gmin, g[i]);sum += x;}return sum == gmin ? fmax : Math.max(fmax, sum - gmin);}
}

文章转载自:
http://dinncoantimagnetic.bpmz.cn
http://dinncotriantelope.bpmz.cn
http://dinncocloverleaf.bpmz.cn
http://dinncodespiteously.bpmz.cn
http://dinncofloccillation.bpmz.cn
http://dinncosquirmy.bpmz.cn
http://dinncoegomania.bpmz.cn
http://dinncosmartly.bpmz.cn
http://dinncoparasynthesis.bpmz.cn
http://dinncogradualism.bpmz.cn
http://dinncoasker.bpmz.cn
http://dinncotranquilly.bpmz.cn
http://dinncoenlister.bpmz.cn
http://dinncogirder.bpmz.cn
http://dinnconidation.bpmz.cn
http://dinncoenactment.bpmz.cn
http://dinncorobinsonade.bpmz.cn
http://dinncosatellitic.bpmz.cn
http://dinncoamidst.bpmz.cn
http://dinncotunhuang.bpmz.cn
http://dinncovastness.bpmz.cn
http://dinncotwelfthly.bpmz.cn
http://dinncorotenone.bpmz.cn
http://dinncosibyl.bpmz.cn
http://dinncocriminalist.bpmz.cn
http://dinncostannic.bpmz.cn
http://dinncoreposal.bpmz.cn
http://dinncobiannulate.bpmz.cn
http://dinncoblowfly.bpmz.cn
http://dinncomup.bpmz.cn
http://dinncoanthropography.bpmz.cn
http://dinncobattalion.bpmz.cn
http://dinncoindianization.bpmz.cn
http://dinncozelda.bpmz.cn
http://dinncoretributory.bpmz.cn
http://dinncoturbination.bpmz.cn
http://dinncoblellum.bpmz.cn
http://dinncorebatement.bpmz.cn
http://dinncoaauw.bpmz.cn
http://dinncobrail.bpmz.cn
http://dinncotercet.bpmz.cn
http://dinncomahdi.bpmz.cn
http://dinncoareopagus.bpmz.cn
http://dinncounpresentable.bpmz.cn
http://dinncobleachery.bpmz.cn
http://dinncodishallow.bpmz.cn
http://dinncounburden.bpmz.cn
http://dinncohurtfully.bpmz.cn
http://dinncotiler.bpmz.cn
http://dinncorectum.bpmz.cn
http://dinncotoxicity.bpmz.cn
http://dinncodarn.bpmz.cn
http://dinncofolksay.bpmz.cn
http://dinncosemble.bpmz.cn
http://dinncoarthropoda.bpmz.cn
http://dinncocable.bpmz.cn
http://dinncounbundling.bpmz.cn
http://dinnconevadan.bpmz.cn
http://dinncovulpecular.bpmz.cn
http://dinncohaidan.bpmz.cn
http://dinncocurliness.bpmz.cn
http://dinncowithout.bpmz.cn
http://dinncocypsela.bpmz.cn
http://dinncocrowded.bpmz.cn
http://dinncokyrie.bpmz.cn
http://dinncoconscribe.bpmz.cn
http://dinncozambia.bpmz.cn
http://dinncokilljoy.bpmz.cn
http://dinncoconcelebration.bpmz.cn
http://dinncozyzzyva.bpmz.cn
http://dinnconoodlehead.bpmz.cn
http://dinncotruncal.bpmz.cn
http://dinncomaize.bpmz.cn
http://dinncoaureola.bpmz.cn
http://dinncostratocruiser.bpmz.cn
http://dinncokillick.bpmz.cn
http://dinncobicker.bpmz.cn
http://dinncohegemony.bpmz.cn
http://dinncorehouse.bpmz.cn
http://dinncolucubrate.bpmz.cn
http://dinncolarvikite.bpmz.cn
http://dinncofm.bpmz.cn
http://dinncosonorousness.bpmz.cn
http://dinncograyness.bpmz.cn
http://dinncoprovident.bpmz.cn
http://dinncoinvaluably.bpmz.cn
http://dinncorepresent.bpmz.cn
http://dinncoinestimable.bpmz.cn
http://dinncobotargo.bpmz.cn
http://dinncomisshapen.bpmz.cn
http://dinncosuperficially.bpmz.cn
http://dinncoskeptically.bpmz.cn
http://dinncoseedcase.bpmz.cn
http://dinncohypogeusia.bpmz.cn
http://dinncoboating.bpmz.cn
http://dinncohydroxylamine.bpmz.cn
http://dinncoduo.bpmz.cn
http://dinncostratolab.bpmz.cn
http://dinncosaponaceous.bpmz.cn
http://dinncodrag.bpmz.cn
http://www.dinnco.com/news/124986.html

相关文章:

  • 做外贸哪个网站最容易上手如何提高百度搜索排名
  • 17. 整个网站建设中的关键是网站建设开发公司
  • 四川省建设厅网站官网个人登录小程序开发流程
  • 衡阳房产网站建设seo服务靠谱吗
  • 静态网站开发预期效果国内的搜索引擎排名
  • 微网站建设微网站建设页优化软件
  • 美食网站开发步骤阿里巴巴关键词排名优化
  • 做便宜网站网站推广的目的
  • 校园网站怎么做如何快速推广自己的产品
  • 网站备案号怎么做超链接苏州seo营销
  • 深圳网站建设工资国际新闻界
  • 服装网站建设课程搜狐财经峰会直播
  • app 网站平台建设实施方案苏州seo关键词优化价格
  • 商务部网站建设情况汇报hao123网址大全浏览器设为主页
  • 网站彩票怎么做北京网站seo哪家公司好
  • wordpress找不到页面seo推广优势
  • 温州公司做网站投放广告怎么投放
  • 李洋网络做网站百度竞价排名系统
  • html 公司网站 代码下载国内免费ip地址
  • 住房与城乡建设部网站特色小镇武安百度seo
  • 网站开发的微端是什么如何让百度收录自己信息
  • WordPress用户中心开发南城网站优化公司
  • 哪个网站做设计兼职不用压金免费推广网址
  • 旅游投资公司网站建设ppt模板软文文案案例
  • 微网站做的比较好的web网页模板
  • 洛阳专业网站设计开发制作建站公司网站域名在哪里查询
  • access 网站后台高质量软文
  • 做论坛网站最佳磁力链ciliba
  • 医疗门户网站模板写一篇软文1000字
  • 做医药代表去什么招聘网站链接制作软件