huangriq

导航

2012年9月7日 #

hdu 3652(数位dp)

摘要: 题意:求解x,y区间中有13字串并且能出13的数的个数思路:数位dp+记忆化搜索,dp[i][j][k]表示处理到第i位,mod13的余数为j,且状态为k的数的个数。k=0表示已经出现了串13,k=2表示前一个数字是1,k=1表示剩余状态。最终结果为dp[pos][0][0]pos为数的位数。View Code 1 #include<iostream> 2 #include<algorithm> 3 #include<cstdio> 4 #include<cstring> 5 #include<cmath> 6 using names 阅读全文

posted @ 2012-09-07 22:09 huangriq 阅读(234) 评论(0) 推荐(0)

hdu 3709(数位dp)

摘要: 题意:给出x,y,求出x到y这个区间的平衡数个数。平衡数定义如题:http://acm.hdu.edu.cn/showproblem.php?pid=3709思路:数位dp,记忆化搜索,dp[pos][rol][pre],pos表示当前位位置,rol表示轴的位置,pre表示当前状态下的权值大小。当pos=-1时表示数位处理完毕,检查结果并返回。当pre<0时返回函数。limit表示是否有上限。View Code 1 #include<iostream> 2 #include<cstdio> 3 #include<algorithm> 4 #includ 阅读全文

posted @ 2012-09-07 22:02 huangriq 阅读(169) 评论(0) 推荐(0)

poj 2486(树形dp)

摘要: 题意:给出一棵树,每个顶点有个权值,求解从顶点1出发经过不超过k条边,经过的顶点的权值和最大值。思路:树形dp,dp[i][j][k],以第i个顶点为根的子树,经过j条边状态为k时经过顶点的最大权值和.k=0表示回到点i,k=1表示不回到点i。View Code 1 #include<algorithm> 2 #include<cstring> 3 #include<vector> 4 using namespace std; 5 #define N 110 6 #define K 220 7 int mx,k; 8 vector<int> g[ 阅读全文

posted @ 2012-09-07 21:51 huangriq 阅读(204) 评论(0) 推荐(0)

poj 1947(树形dp)

摘要: 题意:给出一颗树,求解截出k个连通点需要去掉的最少边树思路:树形dp,dp[i][j] 表示以编号为i的点为根的子树包含j个连通点的最小代价。其中dp[i][1]就是该顶点的分支个数。View Code 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<vector> 6 using namespace std; 7 #define inf 0x3f3f3f 8 #define N 155 9 vec 阅读全文

posted @ 2012-09-07 21:41 huangriq 阅读(147) 评论(0) 推荐(0)