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

怎么用百度云做网站空间asp网站500错误iis7

怎么用百度云做网站空间,asp网站500错误iis7,建设信用卡银行商城网站,浏览器无法访问网页怎么办714. 买卖股票的最佳时机含手续费 原题链接#xff1a;完成情况#xff1a;解题思路#xff1a;ExplanationSummary 参考代码#xff1a;_714买卖股票的最佳时机含手续费 错误经验吸取 原题链接#xff1a; 714. 买卖股票的最佳时机含手续费 https://leetcode.cn/probl… 714. 买卖股票的最佳时机含手续费 原题链接完成情况解题思路ExplanationSummary 参考代码_714买卖股票的最佳时机含手续费 错误经验吸取 原题链接 714. 买卖股票的最佳时机含手续费 https://leetcode.cn/problems/best-time-to-buy-and-sell-stock-with-transaction-fee/description/ 完成情况 解题思路 Sure, let’s break down the code and explain it step by step. The problem is to maximize the profit from buying and selling stocks given that there is a transaction fee each time you sell a stock. You can perform as many transactions as you like, but you must sell the stock before you can buy again. Explanation Initialization: int n prices.length; int [][] dp new int[n][2]; dp[0][0] 0; dp[0][1] -prices[0];n is the length of the prices array.dp is a 2D array where dp[i][0] represents the maximum profit at day i when you don’t have any stock, and dp[i][1] represents the maximum profit at day i when you have one stock.On day 0, if you don’t own a stock, the profit is 0 (dp[0][0] 0).On day 0, if you own a stock, the profit is -prices[0] because you bought the stock at prices[0] (dp[0][1] -prices[0]). DP Transition: for (int i 1; i n; i){dp[i][0] Math.max(dp[i-1][0], dp[i-1][1] prices[i] - fee);dp[i][1] Math.max(dp[i-1][1], dp[i-1][0] - prices[i]); }For each day i from 1 to n-1, we update the dp array: dp[i][0] can be obtained by either: Doing nothing on day i, hence dp[i][0] dp[i-1][0].Selling the stock on day i, hence dp[i][0] dp[i-1][1] prices[i] - fee (selling the stock gives the price at day i, but we must subtract the transaction fee). dp[i][1] can be obtained by either: Doing nothing on day i, hence dp[i][1] dp[i-1][1].Buying the stock on day i, hence dp[i][1] dp[i-1][0] - prices[i] (we subtract the price at day i from the profit since we are buying the stock). Result: return dp[n-1][0];At the end of the loop, dp[n-1][0] will contain the maximum profit we can achieve on the last day if we don’t own any stock (which is the desired result since we want to end up with no stock to realize the profit). Summary The algorithm uses dynamic programming to keep track of the maximum profit for each day, considering both states of holding a stock or not holding a stock.The transition equations consider the profit from both holding and selling a stock, incorporating the transaction fee.Finally, the algorithm returns the maximum profit achievable by the end of the last day when no stock is held. 参考代码 _714买卖股票的最佳时机含手续费 package leetcode板块;public class _714买卖股票的最佳时机含手续费 {/**** param prices* param fee* return*/public int maxProfit(int[] prices, int fee) {// 你可以无限次地完成交易但是你每笔交易都需要付手续费。如果你已经购买了一个股票在卖出它之前你就不能再继续购买股票了。// 返回获得利润的最大值。int n prices.length;int [][] dp new int[n][2];// 0 代表当前股票的空余情况, 1代表当前股票处于抛售的情况dp[0][0] 0;dp[0][1] -prices[0];// TODO 交易的过程中引入卖出时的手续费for (int i 1; i n; i){dp[i][0] Math.max(dp[i-1][0],dp[i-1][1] prices[i] - fee);dp[i][1] Math.max(dp[i-1][1],dp[i-1][0] - prices[i]);}return dp[n-1][0];} } 错误经验吸取
http://www.hkea.cn/news/14257069/

相关文章:

  • 网站开发需求统计php免费开源crm系统
  • 怎样做国际网站安徽省人事考试网
  • 长沙网站制作公司报价青岛seo网站排名优化
  • 福建住房与城乡建设网站网络文化经营许可证申请
  • 自己的电脑如何做网站建行手机app下载
  • 做互联网需要网站吗ui设计的流程有哪些步骤
  • 潮州网站设计中国菲律宾争议岛屿
  • 哪些外贸网站可以做soho绍兴住房和城乡建设厅网站
  • 南充网站建设网站百度快照什么意思
  • 招聘网站建设保定新闻发布会是一种
  • 百度推广网站必须备案吗网站开发按工时收费
  • 网站建设lnmp西安优惠电商平台网站
  • 学习制作网页的网站可以帮忙做网站做公司
  • 关于对网站建设情况的通报沈阳建设工程招标信息网
  • 酒店网站建设流程企业培训网站模板
  • 招投标网站建美食网站有哪些原因
  • 网站标题栏怎么做微信网站建设流程图
  • 免费个人网站注册WordPress二维码管理插件
  • 如需手机网站建设广州网站建设 名片制作 网站管理
  • 艺术名画网站怎么建设彩票网站开发极云
  • 廊坊做网站教程外包公司简介
  • 网站关键词搜索排名怎么做用ps怎么做网站首页
  • 惠州seo外包v1seo查询价格
  • 建设企业网站的重要性wordpress安装主题提示错误
  • 公司集团网站设计深圳企业网站制作流程
  • 如何创建平台类网站wordpress编辑器 代码
  • 单网页网站如何做搞定设计网站做的图怎么下载不了
  • 哈尔滨网站制作哪家好广州网络在线推广
  • 云南省建设厅一级建造师网站深圳网站设计报价
  • 口碑好的网站建设uc网页浏览器网页版