摘要: 1 #include <cstdio> 2 #include <iostream> 3 #include <vector> 4 using namespace std; 5 6 7 8 /* 9 dp[i][0] 表示第i天持有股票所得最多现金, 10 dp[i][1] 表示第i天不持有股票所得最多 阅读全文
posted @ 2025-05-11 16:32 FYJUN2077 阅读(3) 评论(0) 推荐(0)
摘要: 1 #include <cstdio> 2 #include <iostream> 3 #include <vector> 4 using namespace std; 5 6 7 8 /* 9 dp[i][0] 表示第i天持有股票所得最多现金, 10 dp[i][1] 表示第i天不持有股票所得最多 阅读全文
posted @ 2025-05-11 15:59 FYJUN2077 阅读(2) 评论(0) 推荐(0)
摘要: 1 #include <cstdio> 2 #include <iostream> 3 #include <vector> 4 using namespace std; 5 6 //暴力枚举 7 int MaxProfit1(vector<int>& stocks){ 8 int length = 阅读全文
posted @ 2025-05-11 15:59 FYJUN2077 阅读(2) 评论(0) 推荐(0)
摘要: /* 在一个圆形操场的四周摆放 N 堆石子,现要将石子有次序地合并成一堆, 规定每次只能选相邻的 2 堆合并成新的一堆,并将新的一堆的石子数,记为该次合并的得分。 试设计出一个算法,计算出将 N 堆石子合并成 1 堆的最小得分和最大得分。 洛谷题号:P1880 https://www.luogu.c 阅读全文
posted @ 2025-04-06 16:32 FYJUN2077 阅读(4) 评论(0) 推荐(0)
摘要: #include <cstdio> #include <vector> #include <algorithm> using namespace std; int someman(vector<int> &heights){ int n = heights.size(); vector<int> d 阅读全文
posted @ 2025-03-30 16:39 FYJUN2077 阅读(1) 评论(0) 推荐(0)
摘要: 1 /* 2 导弹拦截问题(也称为最长不上升子序列问题)是动态规划中的经典问题之一。问题的描述如下: 3 给定一个导弹飞行高度的序列,要求拦截所有导弹。拦截系统有一个限制:每次拦截的导弹高度不 4 能高于前一次拦截的导弹高度。问最少需要多少套拦截系统才能拦截所有导弹,或者一套拦截系统最多能拦截多少导 阅读全文
posted @ 2025-03-30 16:01 FYJUN2077 阅读(6) 评论(0) 推荐(0)
摘要: 1 #include <iostream> 2 #include <vector> 3 #include <algorithm> 4 using namespace std; 5 6 // 自顶向下的方式 7 pair<int, vector<int>> maximumTotal(vector<ve 阅读全文
posted @ 2025-03-16 16:40 FYJUN2077 阅读(3) 评论(0) 推荐(0)
摘要: 1 /* 2 给定一个无序的整数数组,找到其中最长上升子序列的长度。 3 子序列是由数组派生而来的序列,删除(或不删除)数组中的元素而不改变其余元素的顺序。 4 例如,[3,6,2,7] 是数组 [0,3,1,6,2,2,7] 的一个子序列。 5 6 7 */ 8 9 #include <iostr 阅读全文
posted @ 2025-03-16 15:22 FYJUN2077 阅读(3) 评论(0) 推荐(0)
摘要: 1 /* 2 假设你正在爬楼梯。需要 n 阶你才能到达楼顶。 3 每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢? 4 5 示例 1: 6 输入:n = 2 7 输出:2 8 解释:有两种方法可以爬到楼顶。 9 1. 1 阶 + 1 阶 10 2. 2 阶 11 12 示例 2 阅读全文
posted @ 2025-03-09 15:09 FYJUN2077 阅读(2) 评论(0) 推荐(0)
摘要: /* 线性DP问题 leetcode 53 给你一个整数数组 nums ,请你找出一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和。 子数组是数组中的一个连续部分。 示例 1: 输入:nums = [-2,1,-3,4,-1,2,1,-5,4] 输出:6 解释:连续子数组 [4,- 阅读全文
posted @ 2025-03-02 16:27 FYJUN2077 阅读(4) 评论(0) 推荐(0)