Shirlies
宁静专注认真的程序媛~
posts - 222,comments - 49,views - 71万

随笔分类 -  acm_dp

DP训练1009
摘要:http://acm.hdu.edu.cn/webcontest/contest_show.php?cid=3404DP专题训练一道整数划分的题目将M个蛋糕放在N个盘子里面当M>N时,可以先在每个盘子里面放一个蛋糕,剩下M-N的蛋糕放在N个盘子里面,也可以腾出一个盘子来,用剩下的盘子放M的蛋糕,则f(N,M)=f(N,M-N)+f(N-1,M);当M=N时,可以每个盘子放一个蛋糕,也可以空闲一个盘子,则f(N,M) = f(N-1,M) + 1;当M< N 时,肯定会空盘子,则f(N,M) = f(N-1,M);代码如下: 1 #include <iostream> 2 阅读全文
posted @ 2012-10-17 22:48 Shirlies 阅读(474) 评论(0) 推荐(0) 编辑
hdu 1502【Regular Words】
摘要:不是自己推出来的公式,看题解了才知道这个三维DP公式dp[i][j][k] = dp[i-1][j][k] + dp[i][j-1][k] + dp[i][j][k-1](i >= j >= k)一看到这个题目,我的反应竟然是卡特兰数(一个有n个X和n个Y组成的字串,且所有的部分字串皆满足X的个数大于等于Y的个数。以下为长度为6的dyck words:XXXYYY XYXXYY XYXYXY XXYYXY XXYXYY),n<=60,即使不是卡特兰数,结果应该也会很大,所以要用到大数相加(真心的讨厌写大数相加相乘相除等的代码,磨蹭了些许时间,才写@_@,唉,什么时候自己写个有 阅读全文
posted @ 2012-08-18 12:16 Shirlies 阅读(585) 评论(0) 推荐(0) 编辑
hdu 1422【重温世界杯】
摘要:就这样A了……我的思路大致是:获得生活费与花费的差(在纸上演练一下就清楚为什么了),这一题是求序列和要大于等于0的最长子序列,并且该序列的第一个值必须>=0,还有一个地方就是这是一个圆圈,即从第N个数可以回头转到第一个值,但是最多也就是转一圈,即将该序列浏览两遍,但是转到第一个值的条件是dp[n] > 0,因为只有最后一个dp值大于0的时候转到前面才有意义,试问,如果最后一个dp值小于等于0,都已经欠钱了,早就被踢出德国了……然后为了方便可以将dp[n]存在dp[0]里面……还有一个问题是浏览第一遍数组时,如果所得值已经大于n了,就没有必要继续了,给maxn直接赋值n就可以退出循环 阅读全文
posted @ 2012-08-16 22:19 Shirlies 阅读(387) 评论(0) 推荐(0) 编辑
hdu 1224【Free DIY Tour】
摘要:如果从i->j有路的话,dp[j] = max(dp[j],dp[i]+value[j]),并记录下path[j],如果选择的是dp[i]+value[j],则path[j] = i;之后回溯就可以找到所有路径了……其实这一题可以用压缩版的数组(其实一维数组啦)存储是否有路径,可以节约一半的空间(因为一个地方只有到另外一个编号比它大的城市的路),为了方便我还是用的二维数组^_^代码如下: 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 5 int dp[105]; 6 阅读全文
posted @ 2012-08-16 20:54 Shirlies 阅读(221) 评论(0) 推荐(0) 编辑
hdu 1081【To The Max】
摘要:不知道0ms思路是咋样的,偶滴代码15ms……就是转换成一维数组,然后求最大子序列和……代码如下: 1 #include <cstdio> 2 #include <cstring> 3 4 int n; 5 int inp[105][105]; 6 int temp[105][105]; 7 8 int get_sum(int t[]) 9 {10 int dp[105];11 12 dp[0]= t[0];13 for(int i = 1;i < n;i ++)14 {15 if(dp[i-1]>= 0)16 dp[... 阅读全文
posted @ 2012-08-15 17:35 Shirlies 阅读(168) 评论(0) 推荐(0) 编辑
hdu 1078【FatMouse and Cheese】
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1078人家说是简单题,我说是神题,这个就是大大滴差距\可怜神奇的DP+记忆化搜索只要将各个方向递归退栈后得到的最大值用dp[x][y](这里的最优就是各个方向上的最大值加上此处的cheese)记录下来,以后如果再次搜索到这个地方时可以直接返回该处的值……ps一句:看了别人的题解后才弄出来的……代码如下: 1 #include <cstdio> 2 #include <cstring> 3 4 int dp[105][105]; 5 int inp[105][105]; 6 int n, 阅读全文
posted @ 2012-08-15 16:16 Shirlies 阅读(183) 评论(0) 推荐(0) 编辑
hdu 1025
摘要:啥也不说,就是求最长递增子序列,就说这一题的输出,偶服了,还要分复数和单数……囧死了……代码就不贴了…… 阅读全文
posted @ 2012-08-15 00:44 Shirlies 阅读(282) 评论(0) 推荐(1) 编辑
hdu 1978【How many ways】
摘要:搞了点搜索,IDA*那个启发函数太难找了,先放一放,来搞DP,至于DP的题目是根据http://www.cppblog.com/doer-xee/archive/2009/12/05/102629.html这个地方的内容来的,很全面……这一题还比较好搞……处理当前点,看当前点可达哪一些点……代码如下: 1 #include <cstdio> 2 #include <cstring> 3 4 const int mod = 10000; 5 int map[105][105]; 6 int dp[105][105]; 7 8 int main() 9 {10 int n, 阅读全文
posted @ 2012-08-14 19:42 Shirlies 阅读(268) 评论(0) 推荐(0) 编辑
uva 10405
摘要:晕,最基本的dp题,最长公共子序列。。。。。。竟然没有考虑到空格,衰衰地wa了几次。。。。。。View Code 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 5 const int maxn = 1010; 6 int dp[maxn][maxn]; 7 char s1[maxn]; 8 char s2[maxn]; 9 10 int main() 11 { 12 while(gets(s1) != NULL) 13 { 14 gets(s2); 15 int len1 阅读全文
posted @ 2012-04-07 16:20 Shirlies 阅读(407) 评论(0) 推荐(0) 编辑
uva 103
摘要:(~ o ~)~zZ最长子序列。。。。。。View Code 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 6 struct box 7 { 8 int index; 9 int dm[12]; 10 }b[40]; 11 int num,dim; 12 int ins,maxn; 13 int dp[40]; 14 int record[40]; 15 int ans[40]; 16 17 bool cmp(const box 阅读全文
posted @ 2012-04-07 15:49 Shirlies 阅读(287) 评论(0) 推荐(0) 编辑
uva 111
摘要:这一题题意理解起来有点困难,汗,这个对题目意思解释比较详细,我是看了这个题目解释才做出来的http://www.byywee.com/page/M0/S259/259491.htmlView Code 1 #include <cstdio> 2 #include <cstring> 3 4 int in[30]; 5 int right[30]; 6 int dp[30]; 7 int b[30]; 8 9 int main() 10 { 11 int n; 12 int a; 13 scanf("%d",&n); 14 for(int i 阅读全文
posted @ 2012-04-07 11:23 Shirlies 阅读(345) 评论(0) 推荐(0) 编辑
hdu acm 1069
摘要:题目:http://acm.hdu.edu.cn/showproblem.php?pid=1069这一题够折磨人,这一题难度在dp中只是1难度值,害惨我了,不过也学到了不少东西#include <iostream>#include "algorithm"using namespace std;struct blocks{int x,y,z;}jm[3*31];int dp[3*31];bool cmp(blocks a,blocks b)//这个sort排序要用到的东西,起初我是用指针的,汗,错死我了,我在想我到底应该怎样解决这类问题啊,找不到问题,思路又没有问 阅读全文
posted @ 2011-12-08 20:51 Shirlies 阅读(428) 评论(0) 推荐(0) 编辑

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示