![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
dp
文章平均质量分 75
__1_1__
这个作者很懒,什么都没留下…
展开
-
矩阵中严格递增的单元格数
以max(dp[i][p])的计算为例,若有两个位置(i, j0)和(i, j1), 且mat[i][j0] = mat[i][j1] + 1(只要mat[i][j1]是第i行中仅次于mat[i][j0]的值就行了),目前已知dp[i][j0],那么(i, j1)的max(dp[i][p]) = dp[i][j0] + 1。现在有了dp[i][p]和dp[q][j],就剩下max(dp[i][p])和max(dp[q][j])的计算。初看题目,位置(i, j),只能移动到同行或同列中值严格比他大的位置。原创 2024-06-21 20:19:15 · 630 阅读 · 0 评论 -
访问数组中的位置使分数最大
从获取dp[i]的式子中我们发现其中存在着公共部分,例如max(dp[pi] + nums[i]),每个dp[pi]都要加上nums[i]再进行比较,这是多余的。我们可以直接获取max(dp[pi])再加上nums[i],max(dp[qi] + nums[i] -x)同理也可以优化成 max(dp[qi]) + nums[i] -x。设数组长度为n,每个位置获得的最大得分之和为dp[i] i∈[0,n-1],对于总体的最大得分之和我们需要计算所有dp[i],答案为max(dp[0],…原创 2024-06-14 15:10:52 · 407 阅读 · 0 评论 -
规划兼职工作
力扣:规划兼职工作原创 2022-10-24 13:53:15 · 196 阅读 · 0 评论 -
HDU-2196 Computer
描述A school bought the first computer some time ago(so this computer’s id is 1). During the recent years the school bought N-1 new computers. Each new computer was connected to one of settled earlier...原创 2020-02-19 02:56:27 · 83 阅读 · 0 评论 -
Nearby Cows
描述Farmer John has noticed that his cows often move between nearby fields. Taking this into account, he wants to plant enough grass in each of his fields not only for the cows situated initially in t...原创 2019-12-16 09:55:39 · 165 阅读 · 0 评论 -
Interesting Calculator(dp)
描述There is an interesting calculator. It has 3 rows of buttons.Row 1: button 0, 1, 2, 3, …, 9. Pressing each button appends that digit to the end of the display.Row 2: button +0, +1, +2, +3, …, +9...原创 2019-11-25 21:10:57 · 133 阅读 · 0 评论 -
最短Hamilton路径(状压DP)
描述给定一张 n(n≤20) 个点的带权无向图,点从 0~n-1 标号,求起点 0 到终点 n-1 的最短Hamilton路径。 Hamilton路径的定义是从 0 到 n-1 不重不漏地经过每个点恰好一次。输入第一行一个整数n。接下来n行每行n个整数,其中第i行第j个整数表示点i到j的距离(一个不超过10^7的正整数,记为a[i,j])。对于任意的x,y,z,数据保证 a[x,x...原创 2019-10-24 12:23:18 · 261 阅读 · 0 评论 -
Corn Fields(状压DP)
描述Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ≤ 12) square parcels. He wants to grow some yummy corn for the cows on a number of squares. Regrettab...原创 2019-10-24 11:02:22 · 344 阅读 · 0 评论 -
TOJ 1072: 编辑距离
描述假设字符串的基本操作仅为:删除一个字符、插入一个字符和将一个字符修改成另一个字符这三种操作。我们把进行了一次上述三种操作的任意一种操作称为进行了一步字符基本操作。下面我们定义两个字符串的编辑距离:对于两个字符串a和b,通过上述的基本操作,我们可以把a变成b或b变成a,那么字符串a变成字符串b需要的最少基本字符操作步数称为字符串a和字符串b的编辑距离。例如:a=“ABC”,b=“CBC...原创 2019-09-02 11:21:27 · 393 阅读 · 0 评论