原博客地址 https://blog.csdn.net/androidchanhao/article/details/81271077 题目链接 https://leetcode.com/problems/stone-game/discuss/ https://leetcode-cn.com/contest/weekly-contest-95/problems/stone-game/ 877. 石子游戏 亚历克斯和李用几堆石子在做游戏.偶数堆石子排成一行,每堆都有正整数颗石子 piles[i]…
详解动态规划(Dynamic Programming)& 背包问题 引入 有序号为1~n这n项工作,每项工作在Si时间开始,在Ti时间结束.对于每项工作都可以选择参加与否.如果选择了参与,那么自始至终都必须全程参与.此外,参与不同工作的时间段不能重叠.目标是参与尽可能多的工作,问最多能参与多少项工作? 这个问题乍一看有点棘手,由于每项工作间有时间段的重叠问题,而导致可能选了某个工作后接下去的几个选不了了.所以并不是简单地从起始时间开始,每次在可选的工作中选最早遇上的会达到最优. 事实上,不从遍历…
Alex and Lee play a game with piles of stones.  There are an even number of piles arranged in a row, and each pile has a positive integer number of stones piles[i]. The objective of the game is to end with the most stones.  The total number of stones…
一.字符串常用的操作 1. string类 1.1 string的定义与初始化 1.1.1 string的定义 1.1.2 string的初始化 1.2 string的赋值与swap.大小操作.关系运算 1.2.1 string的赋值与swap 1.2.2 string的大小操作 1.2.3 string的关系运算 1.3 string的访问.插入.删除 1.3.1 string的访问 1.3.2 string的插入 1.3.3 string的删除 1.4 string类的搜索操作 1.5 st…
原题链接在这里:https://leetcode.com/problems/stone-game/ 题目: Alex and Lee play a game with piles of stones.  There are an even number of piles arranged in a row, and each pile has a positive integer number of stones piles[i]. The objective of the game is to…
这个开始自己做的动态规划复杂度达到了O(n), 是用的是2维的矩阵来存前面的数据,复杂度太高了, 虽然好理解,但是没效率,后面看这个博客发现没有动态规划做了这个题 也是比较厉害. 转载地址: https://blog.csdn.net/camellhf/article/details/52824234#commentBox LeetCode 413. Arithmetic Slices 解题报告 题目描述 A sequence of number is called arithmetic if…
Alex and Lee play a game with piles of stones.  There are an even number of piles arranged in a row, and each pile has a positive integer number of stones piles[i]. The objective of the game is to end with the most stones.  The total number of stones…
题目描述 给定一个平衡括号字符串 S,按下述规则计算该字符串的分数: () 得 1 分. AB 得 A + B 分,其中 A 和 B 是平衡括号字符串. (A) 得 2 * A 分,其中 A 是平衡括号字符串. 示例 1: 输入: "()" 输出: 1 示例 2: 输入: "(())" 输出: 2 示例 3: 输入: "()()" 输出: 2 示例 4: 输入: "(()(()))" 输出: 6 提示: S 是平衡括号字符串,…
题目详情 给定字符串 s 和 t ,判断 s 是否为 t 的子序列. 你可以认为 s 和 t 中仅包含英文小写字母.字符串 t 可能会很长(长度 ~= 500,000),而 s 是个短字符串(长度 <=100). 字符串的一个子序列是原始字符串删除一些(也可以不删除)字符而不改变剩余字符相对位置形成的新字符串.(例如,"ace"是"abcde"的一个子序列,而"aec"不是). 示例 1: s = "abc", t =…
题目详情 给定一个字符串 S 和一个字符串 T,计算在 S 的子序列中 T 出现的个数. 一个字符串的一个子序列是指,通过删除一些(也可以不删除)字符且不干扰剩余字符相对位置所组成的新字符串.(例如,"ACE" 是 "ABCDE" 的一个子序列,而 "AEC" 不是) 示例 1: 输入: S = "rabbbit", T = "rabbit" 输出: 3 解释: 如下图所示, 有 3 种可以从 S 中得到…