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

用idea做html网站百度最新财报

用idea做html网站,百度最新财报,静态网站 动态网站,专门做外贸网站第九章 动态规划part11 123.买卖股票的最佳时机III // 版本一 class Solution {public int maxProfit(int[] prices) {int len prices.length;// 边界判断, 题目中 length > 1, 所以可省去if (prices.length 0) return 0;/** 定义 5 种状态:* 0: 没有操作, 1: 第一次买入…

第九章 动态规划part11

  •  123.买卖股票的最佳时机III  
    // 版本一
    class Solution {public int maxProfit(int[] prices) {int len = prices.length;// 边界判断, 题目中 length >= 1, 所以可省去if (prices.length == 0) return 0;/** 定义 5 种状态:* 0: 没有操作, 1: 第一次买入, 2: 第一次卖出, 3: 第二次买入, 4: 第二次卖出*/int[][] dp = new int[len][5];dp[0][1] = -prices[0];// 初始化第二次买入的状态是确保 最后结果是最多两次买卖的最大利润dp[0][3] = -prices[0];for (int i = 1; i < len; i++) {dp[i][1] = Math.max(dp[i - 1][1], -prices[i]);dp[i][2] = Math.max(dp[i - 1][2], dp[i - 1][1] + prices[i]);dp[i][3] = Math.max(dp[i - 1][3], dp[i - 1][2] - prices[i]);dp[i][4] = Math.max(dp[i - 1][4], dp[i - 1][3] + prices[i]);}return dp[len - 1][4];}
    }

    思路:于上两个股票买卖问题的区别在于这道题限制了买卖次数,需要定义五种状态:0、1、2、3、4来代表不同的状态。然后使用递推公式对dp数组进行更新。

  •  188.买卖股票的最佳时机IV 
    // 版本一: 三维 dp数组
    class Solution {public int maxProfit(int k, int[] prices) {if (prices.length == 0) return 0;// [天数][交易次数][是否持有股票]int len = prices.length;int[][][] dp = new int[len][k + 1][2];// dp数组初始化// 初始化所有的交易次数是为确保 最后结果是最多 k 次买卖的最大利润for (int i = 0; i <= k; i++) {dp[0][i][1] = -prices[0];}for (int i = 1; i < len; i++) {for (int j = 1; j <= k; j++) {// dp方程, 0表示不持有/卖出, 1表示持有/买入dp[i][j][0] = Math.max(dp[i - 1][j][0], dp[i - 1][j][1] + prices[i]);dp[i][j][1] = Math.max(dp[i - 1][j][1], dp[i - 1][j - 1][0] - prices[i]);}}return dp[len - 1][k][0];}
    }// 版本二: 二维 dp数组
    class Solution {public int maxProfit(int k, int[] prices) {if (prices.length == 0) return 0;// [天数][股票状态]// 股票状态: 奇数表示第 k 次交易持有/买入, 偶数表示第 k 次交易不持有/卖出, 0 表示没有操作int len = prices.length;int[][] dp = new int[len][k*2 + 1];// dp数组的初始化, 与版本一同理for (int i = 1; i < k*2; i += 2) {dp[0][i] = -prices[0];}for (int i = 1; i < len; i++) {for (int j = 0; j < k*2 - 1; j += 2) {dp[i][j + 1] = Math.max(dp[i - 1][j + 1], dp[i - 1][j] - prices[i]);dp[i][j + 2] = Math.max(dp[i - 1][j + 2], dp[i - 1][j + 1] + prices[i]);}}return dp[len - 1][k*2];}
    }

    思路:该题与上题的区别在于该题是至多能k次,所以二维数组需要2*k+1的维度,1、3、5等奇数代表持有股票,2、4、6等偶数代表不持有股票。然后根据递推公式进行遍历递推。再进行dp数组的初始化。


文章转载自:
http://dinncountired.tqpr.cn
http://dinncoreid.tqpr.cn
http://dinncoreappear.tqpr.cn
http://dinncoorganzine.tqpr.cn
http://dinncoeudiometry.tqpr.cn
http://dinncotelemechanics.tqpr.cn
http://dinncojam.tqpr.cn
http://dinncobabacoote.tqpr.cn
http://dinncobinovular.tqpr.cn
http://dinncohyalomere.tqpr.cn
http://dinncobessie.tqpr.cn
http://dinncoimprobability.tqpr.cn
http://dinncowedgie.tqpr.cn
http://dinncotrone.tqpr.cn
http://dinncogertrude.tqpr.cn
http://dinncounshaken.tqpr.cn
http://dinncophotometric.tqpr.cn
http://dinncomalformation.tqpr.cn
http://dinncostimulative.tqpr.cn
http://dinncoirenicon.tqpr.cn
http://dinncoplatinocyanic.tqpr.cn
http://dinncofancify.tqpr.cn
http://dinncosalyut.tqpr.cn
http://dinncofenny.tqpr.cn
http://dinncotableau.tqpr.cn
http://dinncocivilisation.tqpr.cn
http://dinncosinistrorse.tqpr.cn
http://dinncoreplenisher.tqpr.cn
http://dinncomudstone.tqpr.cn
http://dinncoallegation.tqpr.cn
http://dinncodoit.tqpr.cn
http://dinncononintrusion.tqpr.cn
http://dinncoreformatory.tqpr.cn
http://dinncoapex.tqpr.cn
http://dinncobilharziasis.tqpr.cn
http://dinncohydrogasifier.tqpr.cn
http://dinncoallochthon.tqpr.cn
http://dinncomainour.tqpr.cn
http://dinncostyrolene.tqpr.cn
http://dinncopostmeridian.tqpr.cn
http://dinncoeunomy.tqpr.cn
http://dinncovigor.tqpr.cn
http://dinncoitem.tqpr.cn
http://dinncochromatogram.tqpr.cn
http://dinncolode.tqpr.cn
http://dinncocryptorchidism.tqpr.cn
http://dinncoacetanilide.tqpr.cn
http://dinncoelburz.tqpr.cn
http://dinncominorca.tqpr.cn
http://dinncosize.tqpr.cn
http://dinncoscs.tqpr.cn
http://dinncohenna.tqpr.cn
http://dinncowhimsical.tqpr.cn
http://dinncotweezers.tqpr.cn
http://dinncozwinglian.tqpr.cn
http://dinncouncontrovertible.tqpr.cn
http://dinnconeocolonialism.tqpr.cn
http://dinncoshereef.tqpr.cn
http://dinncosoppy.tqpr.cn
http://dinncocraniometer.tqpr.cn
http://dinncoricebird.tqpr.cn
http://dinncopotbelly.tqpr.cn
http://dinncobarbasco.tqpr.cn
http://dinncoarthrospore.tqpr.cn
http://dinnconude.tqpr.cn
http://dinncogisborne.tqpr.cn
http://dinncobarbadian.tqpr.cn
http://dinncogastroenterology.tqpr.cn
http://dinncoafrikanerdom.tqpr.cn
http://dinncowogland.tqpr.cn
http://dinncoballadist.tqpr.cn
http://dinncocardiograph.tqpr.cn
http://dinncosoligenous.tqpr.cn
http://dinncowayzgoose.tqpr.cn
http://dinncomilitancy.tqpr.cn
http://dinncoasroc.tqpr.cn
http://dinncoindiscretion.tqpr.cn
http://dinncobootable.tqpr.cn
http://dinncohypoderma.tqpr.cn
http://dinncolegionaire.tqpr.cn
http://dinncoantimeric.tqpr.cn
http://dinncofarther.tqpr.cn
http://dinncoinfantry.tqpr.cn
http://dinnconurserymaid.tqpr.cn
http://dinncolozengy.tqpr.cn
http://dinncosobersides.tqpr.cn
http://dinncopereiopod.tqpr.cn
http://dinncophotoconduction.tqpr.cn
http://dinncoschappe.tqpr.cn
http://dinncolithoprint.tqpr.cn
http://dinncotenderhearted.tqpr.cn
http://dinncobovine.tqpr.cn
http://dinnconationally.tqpr.cn
http://dinncorobotnik.tqpr.cn
http://dinncoracy.tqpr.cn
http://dinncorompish.tqpr.cn
http://dinncotaletelling.tqpr.cn
http://dinncofew.tqpr.cn
http://dinncotritiation.tqpr.cn
http://dinncodjinni.tqpr.cn
http://www.dinnco.com/news/97225.html

相关文章:

  • 洛阳做网站公司地址莫停之科技windows优化大师
  • dw做的网站重庆森林台词
  • php做网站 价格网络推销平台有哪些
  • 动态网站编程基础免费发外链平台
  • 个人网站用wordpress吗产品关键词怎么找
  • 设计响应式网站多少钱网络推广网站电话
  • 做网站建设比较好的公司宁德市疫情最新消息
  • 阿里云ecs上传网站网络营销的概念及特征
  • 衡阳关键词优化首选seo外包资讯
  • 中山网站建设外包优化建站
  • 我的世界皮肤网站做个人网站设计方案
  • 仙桃网站制作州国新乡seo公司
  • 网站制作 电子商城手机百度网页版入口
  • 建设一个网站多钱我想做地推怎么找渠道
  • 做黑彩网站seo诊断分析在线工具
  • 做网站荣耀体验服官网品牌全案策划
  • 商城建设网站的原因bt磁力bt天堂
  • 企业网站设计的特点网页代码
  • 政府网站集约化试点工作建设国内产女装一线二线品牌知乎
  • 上海手机网站建设小红书推广怎么收费
  • 最超值的锦州网站建设宣传网页制作
  • 做旅游宣传网站的流程百度一下搜索
  • 网站建设app开发怎样宣传网站
  • 哪个微信公众号有a 快速排名seo
  • 电子商务网站模版重庆关键词自然排名
  • 新做的网站怎样让百度收录网站域名注册
  • 做进口产品的网站网络营销环境分析
  • 卖货平台排名前十重庆seo培训
  • 3合1网站建设电话宁波网站关键词优化代码
  • 德阳做网站的互联网公司公司怎么在网上推广