DP
Dejavu1z
做题,总结,不断的学习
展开
-
codeforces 1420C1
题意描述 思路 我们定义dp[i[[0]dp[i[[0]dp[i[[0]为选择偶数的最大和,即最后一步是加法的最大和;dp[i][1]dp[i][1]dp[i][1]为选择奇数的最大和,即最后一步是减法的最大和。得出转移方程: dp[i][0]=max(dp[i−1][0],dp[i−1][1]+a[i])dp[i][0]=max(dp[i-1][0],dp[i-1][1]+a[i])dp[i][0]=max(dp[i−1][0],dp[i−1][1]+a[i]) dp[i][1]=max(dp[i−1]原创 2020-09-27 17:41:41 · 199 阅读 · 0 评论 -
codeforces 455A(dp)
题意描述 Alex doesn’t like boredom. That’s why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence a consisting of n integers. The player can make several steps. In a single st原创 2020-09-24 08:19:14 · 201 阅读 · 0 评论 -
codeforces 1282B(dp)
题目描述 身上有p块钱,可以连续购买k件物品只需要付其中最贵的价钱,求出能够购买物品的最大数量 思路 我们用f[i]f[i]f[i]表示购买前i件商品的最小花费,因为可以连续购买k件物品,所以当i大于k时,得到转移方程f[i]=min(f[i−1],f[i−k])+a[i]f[i]=min(f[i-1],f[i-k])+a[i]f[i]=min(f[i−1],f[i−k])+a[i]。 AC代码 #include<bits/stdc++.h> #define x first #define y原创 2020-07-25 16:32:57 · 156 阅读 · 0 评论 -
POJ2955(区间dp)
题意描述 求最长括号匹配的子序列长度 思路 区间dp的经典题目,我们用f[i][j]f[i][j]f[i][j]来表示从i到j的括号序列,如果s[i]s[i]s[i]和s[j]s[j]s[j]处的字符可以构成字符,那么就有f[i][j]=f[i+1][j−1]+2f[i][j]=f[i+1][j-1]+2f[i][j]=f[i+1][j−1]+2,然后就枚举k来求最值。转移方程如下: f[i][j]=f[i+1][j−1]+2f[i][j]=f[i+1][j-1]+2f[i][j]=f[i+1][j−1]+原创 2020-07-25 14:54:14 · 236 阅读 · 0 评论 -
codeforces 1272D(dp)
题意描述 You are given an array a consisting of n integers. You can remove at most one element from this array. Thus, the final length of the array is n−1 or n. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarra原创 2020-07-23 15:33:41 · 175 阅读 · 0 评论 -
codeforces 544C(完全背包求方案数)
题意描述 Programmers working on a large project have just received a task to write exactly m lines of code. There are n programmers working on a project, the i-th of them makes exactly a i bugs in every line of code that he writes. Let’s call a sequence of non原创 2020-07-21 15:56:43 · 721 阅读 · 0 评论 -
HDU 1059(多重背包)
题意描述 Marsha and Bill own a collection of marbles. They want to split the collection among themselves so that both receive an equal share of the marbles. This would be easy if all the marbles had the same value, because then they could just split the collec原创 2020-07-20 17:36:49 · 114 阅读 · 0 评论 -
POJ 2063(完全背包)
题意描述 John never knew he had a grand-uncle, until he received the notary’s letter. He learned that his late grand-uncle had gathered a lot of money, somewhere in South-America, and that John was the only inheritor. John did not need that much money for the原创 2020-07-20 16:51:57 · 201 阅读 · 1 评论 -
Coins (多重背包二进制优化)
题意描述 Whuacmers use coins.They have coins of value A1,A2,A3…An Silverland dollar. One day Hibix opened purse and found there were some coins. He decided to buy a very nice watch in a nearby shop. He wanted to pay the exact price(without change) and he known原创 2020-07-20 16:22:28 · 494 阅读 · 0 评论 -
codeforce1178B (DP)
题意描述 Recall that string a is a subsequence of a string b if a can be obtained from b by deletion of several (possibly zero or all) characters. For example, for the string a=“wowwo”, the following stri...原创 2020-05-04 08:32:29 · 340 阅读 · 0 评论 -
189A Cut Ribbon(dp)
题意 Polycarpus has a ribbon, its length is n. He wants to cut the ribbon in a way that fulfils the following two conditions: After the cutting each ribbon piece should have length a, b or c. After the ...原创 2020-04-08 20:40:55 · 184 阅读 · 0 评论 -
地宫取宝 (第五届蓝桥杯省赛C++A/B组)
题意描述 X 国王有一个地宫宝库,是 n×m 个格子的矩阵,每个格子放一件宝贝,每个宝贝贴着价值标签。 地宫的入口在左上角,出口在右下角。 小明被带到地宫的入口,国王要求他只能向右或向下行走。 走过某个格子时,如果那个格子中的宝贝价值比小明手中任意宝贝价值都大,小明就可以拿起它(当然,也可以不拿)。 当小明走到出口时,如果他手中的宝贝恰好是 k 件,则这些宝贝就可以送给小明。 请你帮小明算一算,在...原创 2020-03-10 15:58:24 · 376 阅读 · 0 评论