随笔分类 -  DP

hdu 4618 Palindrome Sub-Array
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4618直接DP+记忆化虽然时间复杂度看起来是300^4 但实际执行起来要远远小于这个值 所有可以水过代码:#include#include#include#include#include#include#include#include#include#include#include#include#include#include//#pragma comment(linker, "/STACK:1024000000,1024000000")using namespace std;typed 阅读全文
posted @ 2013-07-25 21:43 夜-> 阅读(178) 评论(0) 推荐(0)
hdu 4610 Cards
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4610先求出每个数的得分情况,分数和得分状态,(1#include#include#include#include#include#include#include#include#include#include#include#include#include#include#includeusing namespace std;typedef long long ll;typedef unsigned int uint;const double eps=1e-12;const int INF=0x3f3f3f 阅读全文
posted @ 2013-07-25 19:25 夜-> 阅读(177) 评论(0) 推荐(0)
Topcoder SRM 584 DIV1 600
摘要:思路太繁琐了 ,实在不想解释了代码:#include#include#include#include#include#include#include#include#include#include#include#define ull unsigned long long#define ll long long#define lint long longusing namespace std;const int INF=0x3f3f3f3f;const int N=53;ll c[N][N];ll dp[N][N][N];ll dp1[N][N][N];class Excavations{ . 阅读全文
posted @ 2013-07-12 17:49 夜-> 阅读(267) 评论(0) 推荐(0)
UVa 10253 - Series-Parallel Networks
摘要:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1194不看解析还真没有什么思路,刘汝佳的《算法竞赛入门经典训练指南》P117将原问题转换成树 然后再进行树型DP代码:#include #include #include #include #include #include #include #define ll long longusing namespace std;const int N=100;ll dp[N][N];ll 阅读全文
posted @ 2013-07-07 18:49 夜-> 阅读(242) 评论(0) 推荐(0)
UVa 11361 - Investigating Div-Sum Property
摘要:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2346数位DP代码:#include #include #include #include #include #include #include #define ll long longusing namespace std;int dp[11][90][10002];int a[11];int c[11];int M;int dfs(int x,int k1,int k2,int 阅读全文
posted @ 2013-07-06 20:12 夜-> 阅读(219) 评论(0) 推荐(0)
LA 3516 - Exploring Pyramids
摘要:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1517久违的树形dpdp[l][r] 表示在l到r之间字符串形成的子树有多少种然后要枚举最左树枝所到位置 假设是 i 那么从l+1到i-1 递归就是最左树枝的种类 然后乘上剩下的部分剩下的部分i到r相当是去掉了最左树枝的又一个子树,递归就可以代码:#include #include #include #include #include #include #inclu 阅读全文
posted @ 2013-07-06 18:59 夜-> 阅读(167) 评论(0) 推荐(0)
sdut 2609 A-Number and B-Number
摘要:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2609数位DP 以前没怎么做过,自己憋了半天,还是看了标程,标程写的就是好呀。相关注释见代码:#include<iostream>#include<cstdio>#include<vector>#include<stack>#include<cstring>#include<queue>#include<algorithm>#include<cmath&g 阅读全文
posted @ 2013-06-18 19:54 夜-> 阅读(278) 评论(0) 推荐(0)
TopCoder SRM 582 ColorfulBuilding
摘要:DP 思路是三维,但是时间肯定会超时,需要根据其特殊性质加两个标记数组,优化成二维。刚开始想了N久N久,没感觉,还是动手画了一下才有用呀,意淫再久,不如动手呀。代码:#include<iostream>#include<cstdio>#include<vector>#include<stack>#include<cstring>#include<queue>#include<algorithm>#include<cmath>#include<cstring>#include<str 阅读全文
posted @ 2013-06-17 11:19 夜-> 阅读(451) 评论(0) 推荐(0)
TopCoder SRM 176 Deranged
摘要:代码:#include<iostream>#include<cstring>#include<cstdio>#include<string>#include<set>#include<map>#include<cmath>#include<algorithm>#include<vector>#include<cmath>#include<queue>#include<stack>//#define ull unsigned long long#defi 阅读全文
posted @ 2013-05-31 21:28 夜-> 阅读(249) 评论(0) 推荐(0)
TopCoder SRM 390 SetOfPatterns
摘要:自己憋了N久也没思路,看了一下别人的代码,神呀,这就是差距呀,继续努力。代码:#include<iostream>#include<cstring>#include<cstdio>#include<string>#include<set>#include<map>#include<cmath>#include<algorithm>#include<vector>#include<cmath>#include<queue>#include<stack>/ 阅读全文
posted @ 2013-05-31 19:54 夜-> 阅读(277) 评论(0) 推荐(0)
TopCoder SRM 382 CharmingTicketsEasy
摘要:这题的主要算法是DP 只在最后结果上用了一下容斥原理代码:#include<iostream>#include<cstring>#include<cstdio>#include<string>#include<set>#include<map>#include<cmath>#include<algorithm>#include<vector>#include<cmath>#include<queue>#include<stack>//#define u 阅读全文
posted @ 2013-05-30 11:36 夜-> 阅读(368) 评论(0) 推荐(0)
hdu 3632 A Captivating Match
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=3632还是做题爽kill[l][r] 表示通过一定策略 l 是否可以把 l -- r 之间的其他所以人都淘汰掉代码:#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<algorithm>#include<cmath>#define ll long longusing namespace std;const int N=105;//cons 阅读全文
posted @ 2013-05-10 16:54 夜-> 阅读(183) 评论(0) 推荐(0)
zoj 2319 Beautiful People
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1319这题给人的第一感觉就是最长上升子序列,按S排序,对B进行求解最长上升子序列,但是N太大o(n^2)肯定不行,所以要用优化,我是用了线段数进行优化。不是经常用类,这次用了一下,还是有很多小问题的,如果在函数内部静态申请一个局部变量对象由于对象内有很大的数组,这样就相当于在函数所占用的栈区内申请了很大数组,没有语法错误,但c++是不允许它执行的换成从堆区申请就好了,不过要记得delete否则会超内存DP思想+线段树优化代码:#include<iostream># 阅读全文
posted @ 2013-05-03 07:26 夜-> 阅读(251) 评论(0) 推荐(0)
zoj 2315 New Year Bonus Grant
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1315简单的树型DP 代码:#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<algorithm>#include<cmath>#include<map>#include<set>#include<vector>#include<stack>#include 阅读全文
posted @ 2013-04-24 16:52 夜-> 阅读(248) 评论(0) 推荐(0)
sgu 104. Little shop of flowers
摘要:http://acm.sgu.ru/problem.php?contest=0&problem=104水题 DP 但是wa了一次 本来应该初始化为负无穷的 结果初始化为0了 细节呀代码:#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<algorithm>#include<cmath>#include<map>#include<set>#include<vector>#inclu 阅读全文
posted @ 2013-04-19 19:45 夜-> 阅读(111) 评论(0) 推荐(0)
C. Greg and Friends
摘要:http://codeforces.com/contest/295/problem/C简单DP代码:#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<algorithm>#include<cmath>#define ll long longusing namespace std;const int N=55;const ll MOD = 1000000007;ll dp[N*4][N][N];ll c[N][N];int 阅读全文
posted @ 2013-04-18 09:33 夜-> 阅读(159) 评论(0) 推荐(0)
hdu 4532 湫秋系列故事——安排座位
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4532细节决定成败呀 ( x * ( y * z ) % mod ) % mod刚开始想的是 先 ( y * z ) 对 mod 取模 然后再 *x 对mod取模后来一想不对呀 (y * z ) 要先 *x 后取模呀脑子短路伤不起呀dp+数学代码:#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<set>#include<map>#inc 阅读全文
posted @ 2013-04-16 21:32 夜-> 阅读(236) 评论(0) 推荐(0)
hdu 4534 郑厂长系列故事——新闻净化
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4534自动机+DP(状态压缩)整体思路应该很明确,但要注意一些细节方面的处理 否则会wa代码:#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<map>#include<set>#include<vector>#include<stack>#include<queue>using namespace s 阅读全文
posted @ 2013-04-04 12:57 夜-> 阅读(216) 评论(0) 推荐(0)
poj 1185 炮兵阵地
摘要:http://poj.org/problem?id=1185状态压缩+dp代码:#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<map>#include<set>#include<vector>#include<stack>#include<queue>#include<algorithm>#define LL long long#define ULL unsigned l 阅读全文
posted @ 2013-04-02 17:28 夜-> 阅读(157) 评论(0) 推荐(0)
hdu 4539 郑厂长系列故事——排兵布阵
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4539状态压缩+dp此题给人感觉状态数比较多 但是由于自身有一定的限制所以说 根本不到(1<<10) 自己测一下的话还不到 200如果再加上输入矩阵的限制 每一行的状态数就更少了 大胆的用for循环就是了可怜的是我在比赛中大脑短路没想到用了一种很恶心的方法 就是把图斜着看 根据左下到右上的方向进行分层,这样第i层只和第i-2层有关了不过在将图斜过来的时候要细心呐代码1:#include<iostream>#include<cstdio>#include<cstring 阅读全文
posted @ 2013-04-02 16:56 夜-> 阅读(226) 评论(0) 推荐(1)