
DP
文章平均质量分 77
ahfywff
这个作者很懒,什么都没留下…
展开
-
HDU 4028 The time of a day
看完题目后觉得要用dp,但是数据量太大,搞不定。看了解题报告后才知道可以用map来离散化。代码如下:#include #include #include using namespace std;const int MAXN = 42;__int64 gcd(__int64 x, __int64 y){ if (y == 0) return x; return g原创 2012-01-14 21:02:15 · 560 阅读 · 0 评论 -
HDU 3401 Trade【单调队列+dp】
题意:已知股票每天的买入和卖出价格、买入上限和卖出上限以及最多能持有的股票数,问n天后的最大收益是多少。#include #include #include #include #include using namespace std;const int oo = 1 << 30;const int maxn = 2010;int tcase;int t, maxp,原创 2012-08-27 16:49:36 · 1159 阅读 · 0 评论 -
HDU 3507 Print Article【斜率优化dp】
斜率优化dp,这篇文章讲的很好。#include #include #include #include #include using namespace std;const int oo = 1LL << 62;const int maxn = 500010;__int64 c[maxn], sum[maxn];__int64 dp[maxn];int q[maxn],原创 2012-08-29 20:40:03 · 1748 阅读 · 0 评论 -
HDU 2829 Lawrence【斜率优化dp】
题意:大概就是给你n(1将“4 5 1 2”分成一组得到的价值为:4*5 + 4*1 + 4*2 + 5*1 + 5*2 + 1*2 = 49;将“4 5 1 2”分成“4 5”和“1 2”两组得到的价值为:4*5 + 1*2 = 22;将“4 5 1 2”分成“4”和“5 1 2”两组得到的价值为:0 + 5*1 + 5*2 + 1*2 = 17。分析:本题可以用动态规划原创 2012-08-30 09:33:03 · 2830 阅读 · 0 评论 -
HDU 4258 Covered Walkway【斜率优化dp】
这题跟HDU3507差不多。#include #include #include #include #include using namespace std;const int maxn = 1000010;int n;__int64 c, x[maxn];__int64 dp[maxn];int q[maxn], head, tail;__int64 dy(int原创 2012-08-29 20:44:46 · 1017 阅读 · 0 评论 -
HDU 4374 One hundred layer(单调队列+DP)
#include #include #include #include #include using namespace std;const int maxn = 111;const int maxm = 10010;const int oo = 1 << 30;int n, m, x, t;int s[maxn][maxm];int sum[maxn][maxm];原创 2012-08-17 20:58:46 · 916 阅读 · 0 评论 -
HDU 4328 Cut the Cake(动态规划)
Problem DescriptionMark bought a huge cake, because his friend ray_sun’s birthday is coming. Mark is worried about how to divide the cake since it’s so huge and ray_sun is so strange. Ray_sun is a原创 2012-08-02 19:19:30 · 719 阅读 · 0 评论 -
HDU 1011 Starship Troopers (树形DP+依赖背包)
dp[i][j]: 以i为根的子树花费为j时的最大收益。dp[i][j] = max(dp[i][j], dp[i][j-k] + dp[son(i)][k])#include #include #include #include #include using namespace std;const int maxn = 111;int n, m;vector son[原创 2012-05-16 22:17:10 · 733 阅读 · 0 评论 -
POJ 4045 Power Station 2012金华邀请赛B题(树形DP)
很早就听说过树形DP了,只是一直没做过这方面的题。这次金华邀请赛出了这道树形DP,是zz_1215做出来的。发现这个考的挺多的,于是就学习了一下。这个题大致意思是给你一颗树,让你求一点,使该点到其余各点的距离之和最小。如果这样的点有多个,则按升序依次输出。我的做法:对于点x定义两个量dp[x]和node[x]。 dp[x]为以节点x为根的子树中x到它后代节点的距离之和;no原创 2012-05-14 15:45:16 · 2690 阅读 · 0 评论 -
HDU 4226 迎接2012新赛季——HDOJ系列热身赛(5)(A题)
动态规划题。因为题目有一个地方看错了,赛后才AC。#include #include #include #include using namespace std;const int maxn = 1111;const double PI = 3.14159265358979323846;const double oo = (1 << 30原创 2012-04-25 21:58:35 · 769 阅读 · 0 评论 -
HDU1503 Advanced Fruits (Dynamic Programming)
先求两字符串的最长公共子序列,并记录公共子序列每个字符在两字符串中的位置。然后,按要求输出结果。详见代码。#include #include #include #include using namespace std;const int maxn = 111;char s1[maxn], s2[maxn], ans[maxn*2];int len[maxn][maxn原创 2012-04-12 22:49:07 · 874 阅读 · 0 评论 -
SGU104 Little Shop of Flowers (DP)
动态规划题用dp[i][j]表示把前i束花放在前j个花瓶里所得到的最大的美观值(i递推式为:dp[i][j] = max(dp[i][j-1], dp[i-1][j-1] + A[i][j]),dp[F][V]即为所求。题目还要求输出每束花的摆放位置,可以用pre[i][j]=0或1表示dp[i][j]是由dp[i][j-1]或dp[i-1][j-1] + A[i][j]得来的,然后递原创 2012-04-08 22:54:32 · 729 阅读 · 0 评论 -
HDU 2993 MAX Average Problem【斜率优化dp】
给由n(n=k的子序列的平均值的最大值。本题O(n^2)的dp算法比较好想,但是n的范围较大,会超时,所以,必须进行优化。这里用到的是斜率优化,《浅谈数形结合思想在信息学竞赛中的应用》这篇论文中有这一题的详细介绍。#include #include #include #include #include using namespace std;const int maxn =原创 2012-08-28 16:59:21 · 1437 阅读 · 2 评论