
—————动态规划———
文章平均质量分 65
Unin88
这个作者很懒,什么都没留下…
展开
-
HDU 1513 Palindrome(LCS+滚动数组)
本题中的动态规划dp[ i ][ j ]第一维只与i - 1有关 ,即只涉及两层, 那么可以用滚动数组来节省空间的消耗,会少许增加时间复杂度原创 2014-08-20 20:10:02 · 613 阅读 · 0 评论 -
DOJ 1309: C111的日常之get the ball
http://acm.dlut.edu.cn/problem.php?id=1309总是觉得这种dp好奇怪!AC代码:#include #include #include #include using namespace std;const int MAX = 35;int dp[MAX][MAX];int main(){ int n,m;原创 2014-12-16 16:32:51 · 557 阅读 · 0 评论 -
HDU 1024 Max Sum Plus Plus
http://acm.hdu.edu.cn/showproblem.php?pid=1024原创 2014-11-08 18:47:55 · 367 阅读 · 0 评论 -
HDU 2845 Beans
http://acm.hdu.edu.cn/showproblem.php?pid=2845输入数据数量很大,我原创 2014-11-06 19:00:58 · 390 阅读 · 0 评论 -
HDU 1421 搬寝室
http://acm.hdu.edu.cn/showproblem.php?pid=1421原创 2014-11-05 22:26:47 · 388 阅读 · 0 评论 -
HDU 2844 Coins
http://acm.hdu.edu.cn/showproblem.php?pid=2844二进制优化的多重背包原创 2014-11-03 22:20:37 · 316 阅读 · 0 评论 -
HDU 2159 FATE
http://acm.hdu.edu.cn/showproblem.php?pid=2159二维原创 2014-11-03 20:47:51 · 316 阅读 · 0 评论 -
HDU 1159 Common Subsequence
http://write.blog.youkuaiyun.com/postedit原创 2014-11-03 23:00:48 · 281 阅读 · 0 评论 -
HDU 1069 Monkey and Banana
http://acm.hdu.edu.cn/showproblem.php?pid=1069原创 2014-11-02 23:50:10 · 439 阅读 · 0 评论 -
SGU 116 Index of super-prime
素数筛+完全背包+路径记录AC代码:#include #include #include #include #include using namespace std;const int MAX = 100010;const int INF = 0x3f3f3f3f;bool IsPrime[MAX];int Prime[MAX],SPrime[MAX],pn,cnt原创 2014-12-16 17:01:15 · 393 阅读 · 0 评论 -
poj 1018 Communication System
B是选中的产品中最小的带宽,P是所有选中的产品的价格之和,目标是是B/P最大。这种有依赖关系的dp问题,应该暂时确定一维,然后求解另一维的最优值。本题中题目有暗示,既然B是最小的带宽,那么我们可以枚举带宽。dp[i][j]代表选择到第i个产品最小带宽为j时的最小花费。#include #include #include #include #include #include原创 2015-01-27 18:26:00 · 419 阅读 · 0 评论 -
hdu 2709 Sumsets
acm.hdu.edu.cn/showproblem.php?pid=2709设a[n]为和为 n 的种类数1.n为奇数,a[n]=a[n-1]2.n为偶数:(1)如果加数里含1,则一定至少有两个1,即对n-2的每一个加数式后面 +1+1,总类数为a[n-2];(2)如果加数里没有1,即对n/2的每一个加数式乘以2,总类数为a[n/2];所以总的种类数为:a[n]=a[n-原创 2015-01-20 10:03:26 · 550 阅读 · 0 评论 -
hdu 3336 Count the string
http://acm.hdu.edu.cn/showproblem.php?pid=3336根据TMP求next数组的原理我们发现:给出任意数字i,它的next值为j(j>0),那么j-1代表str[0]~str[j-1]这个前缀再主串中出现一次。由此轻松解决本题AC代码:#include #include #include #include using na原创 2014-12-24 21:26:18 · 337 阅读 · 0 评论 -
Uva 116 Unidirectional TSP
典型的动态规划问题,类似于数字三角形的感觉。要求字典序路径。#include #include #include #include #include #include #include using namespace std; int v[110][110],dp[110][110],path[110][110];int m,原创 2015-01-30 11:16:13 · 531 阅读 · 0 评论 -
Uva 11584 Partitioning by Palindromes
经典动态规划题求最少分化成多少个回文串,dp[i]表示以i为结尾的最少划分多少个,那么转移方程为dp[i] = min(dp[j]+1) 其中j满足j+1到i是回文串,这其中时间复杂度是O(n^3),可以预先预处理,见程序中的注释。#include #include #include #include #include #include #inclu原创 2015-01-30 21:27:47 · 394 阅读 · 0 评论 -
UVA 1401 Remember the Word
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=36217问一个单词可以如何用所给的一系列单词拆分问题分析:a bcdab cdabc dabcd很容易想到递归:dp[i] = sum(dp[i+len])其中dp[i]是指字符串从i开始的后缀有多少种拆分方式,len是字典中给出的前缀的长度原创 2014-12-23 15:23:13 · 381 阅读 · 0 评论 -
To the Max
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=65411#problem/B预处理sum数组记录a[1][1]到a[i][j]的矩阵的和在dp的时候使用。#include #include #include #include using namespace std;const int INF = 0x3f3原创 2014-12-06 15:06:17 · 405 阅读 · 0 评论 -
Communication System
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=65411#problem/Adp[i][j]代表到达第i行最小带宽为j的最小价格!#include #include #include #include using namespace std;const int INF = 0x3f3f3f3f;int原创 2014-12-06 13:33:23 · 613 阅读 · 0 评论 -
矩形嵌套
题意有n个矩形,每个矩形可以用a,b来描述,表示长和宽。矩形X(a,b)可以嵌套在矩形Y(c,d)中当且仅当a模型建立矩形之间的可嵌套关系是一个典型的二元关系,二元关系可以用图来建模。如果矩形X可嵌套在矩形Y中,就从X向Y连一条有向边。这个有向图是无环的,它是一个DAG。这样所求便是不固定起点和终点的DAG上的最长路。解题过程动态规划DAG中不固定顶点的最长原创 2015-01-30 08:59:33 · 557 阅读 · 0 评论 -
HDU 1505 City Game
http://acm.hdu.edu.cn/showproblem.php?pid=1505原创 2014-11-02 20:31:04 · 328 阅读 · 0 评论 -
HDU 2571 命运
http://acm.hdu.edu.cn/showproblem.php?pid=2571最优化dp原创 2014-11-02 22:56:41 · 373 阅读 · 0 评论 -
HDU 1559 最大子矩阵
http://acm.hdu.edu.cn/showproblem.php?pid=1559先计算sum[i][]原创 2014-11-09 11:12:04 · 423 阅读 · 0 评论 -
HDU 4501 小明系列故事——买年货(多维01背包)
http://acm.hdu.edu.cn/showproblem.php?pid=4501原创 2014-11-09 13:04:21 · 543 阅读 · 0 评论 -
HDU 1081 To The Max
http://acm.hdu.edu.cn/showproblem.php?pid=1081原创 2014-08-23 14:14:01 · 453 阅读 · 0 评论 -
HDU 3127 WHUgirls(矩阵切割)
原创 2014-11-09 12:20:37 · 500 阅读 · 0 评论 -
HDU 2084 数塔
http://acm.hdu.edu.cn/showproblem.php?pid=2084最优解原创 2014-09-22 19:44:23 · 317 阅读 · 0 评论 -
HDU 1231 最大连续子序列
http://acm.hdu.edu.cn/showproblem.php?pid=1231原创 2014-09-22 20:17:33 · 272 阅读 · 0 评论 -
HDU 1864 最大报销额
http://acm.hdu.edu.cn/showproblem.php?pid=1864原创 2014-08-21 15:51:27 · 421 阅读 · 0 评论 -
HDU 3415 Max Sum of Max-K-sub-sequence
本题是需要单调队列的原创 2014-08-21 10:22:00 · 395 阅读 · 0 评论 -
HDU 4508 湫湫系列故事——减肥记I
http://acm.hdu.edu.cn/showproblem.php?pid=4508简单完全背包#include #include #include #include const int N=100010;using namespace std;struct job{ int value,w;}node[N];int n,m,dp[N];in原创 2014-11-09 13:40:53 · 453 阅读 · 0 评论 -
HDU 4502 吉哥系列故事——临时工计划
http://acm.hdu.edu.cn/showproblem.php?pid=4502dp[i]原创 2014-11-09 13:27:28 · 404 阅读 · 0 评论 -
HDU 1506 Largest Rectangle in a Histogram
http://acm.hdu.edu.cn/showproblem.php?pid=1506原创 2014-11-02 19:03:04 · 347 阅读 · 0 评论 -
HDU 1087 Super Jumping! Jumping! Jumping!
http://acm.hdu.edu.cn/showproblem.php?pid=1087最大递增子序列,原创 2014-11-02 22:28:28 · 319 阅读 · 0 评论 -
HDU 1231 最大连续子序列
http://acm.hdu.edu.cn/showproblem.php?pid=1231原创 2014-11-01 16:00:54 · 294 阅读 · 0 评论 -
HDU 1864 最大报销额
http://acm.hdu.edu.cn/showproblem.php?pid=1864原创 2014-11-01 15:33:06 · 673 阅读 · 0 评论 -
HDU 3339 In Action
http://acm.hdu.edu.cn/showproblem.php?pid=3339原创 2014-10-30 23:17:12 · 374 阅读 · 0 评论 -
HDU 2546 饭卡
http://acm.hdu.edu.cn/showproblem.php?pid=2546原创 2014-10-29 14:44:14 · 364 阅读 · 0 评论 -
hdu 1159 Common Subsequence
#include #include #include #include #include using namespace std;char str1[1010],str2[1010];int dp[1010][1010];int main(){// freopen("in.txt", "r", stdin); while(scanf("%s", str1) !原创 2014-10-12 10:11:25 · 331 阅读 · 0 评论 -
HDU 2602 Bone Collector
http://acm.hdu.edu.cn/showproblem.php?pid=2602原创 2014-10-29 14:07:49 · 313 阅读 · 0 评论 -
Two Buttons
求解由n到m只通过-1或*2最少需要多少步,典型动态规划问题,采用记忆化搜索。#include #include #include #include using namespace std; const int INF = 0x3f3f3f3f; int n,m;int dp[20010],vis[20010];int dfs(int u){ if(原创 2015-03-08 19:17:32 · 497 阅读 · 0 评论