上一页 1 ··· 92 93 94 95 96 97 98 99 100 ··· 121 下一页
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1300思路:直接写递推方程式:dp[i]=min{dp[j]+value}(0<=j<i,value为第j+1类珠宝到第i类全部以i类买入的价值; );然后我们可以用一个数组记录一下0-i的花费 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 #define MAXN 1111 阅读全文
posted @ 2013-05-22 17:37 ihge2k 阅读(263) 评论(0) 推荐(0)
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1503思路:如何求最长公共子序列就不说了,另外如果有str2[j]==str1[i],那就mark[i]=j,相当于一个标记。 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 #define MAXN 111 7 int dp[MAXN][MAXN]; 8 char str1[MAXN], 阅读全文
posted @ 2013-05-22 17:02 ihge2k 阅读(475) 评论(0) 推荐(0)
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3535一道需要深刻理解状态转移的背包题:dp[i][j],表示第i组,时间剩余为j时的快乐值。每得到一组工作就进行一次DP,所以dp[i]为第i组的结果。1、至少选一项,即必须要选,那么在开始时,对于这一组的dp的初值,应该全部赋为负无穷,这样才能保证不会出现都不选的情况。状态转移方程为dp[i][k]=max{ dp[i][k],dp[i-1][k-cost[j]]+val[j],dp[i][k-cost[j]]+val[j] }。dp[i][k]是不选择当前工作;dp[i-1][k-cost[j 阅读全文
posted @ 2013-05-21 22:52 ihge2k 阅读(208) 评论(0) 推荐(1)
摘要: 题目链接:http://acm.cug.edu.cn/JudgeOnline/problem.php?id=1317思路:dp[i][j]表示以a[i]为结尾的串与以b[j]为结尾的串的最小编辑距离,则若a[i]==a[j],有dp[i][j]==dp[i-1][j-1];否则dp[i][j]=min{dp[i-1][j-1]+2,dp[i-1][j]+3,dp[i][j-1]+3} 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<string> 5 # 阅读全文
posted @ 2013-05-21 22:36 ihge2k 阅读(219) 评论(0) 推荐(0)
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4526思路:dp[i][j]表示前i辆车送走j个acmer的最小花费,然后就有dp[i][j]=dp[i-1][j-k]+k*t+d;(t为车辆到达的时间,d为花费),值得注意的地方是dp[0][0]=0,而其余都应该初始化为inf. 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 using namespace std; 6 #define 阅读全文
posted @ 2013-05-21 17:20 ihge2k 阅读(208) 评论(0) 推荐(0)
摘要: 题目链接:http://acdreamoj.sinaapp.com/problem.php?id=1083没什么好说的,具体看代码吧。 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 using namespace std; 6 int dp[11][4];//0没有3和8,1只有3,2只有8,3有3和8 7 int digit[11]; 8 9 int dfs(int pos,int have,int doing){10 if(pos 阅读全文
posted @ 2013-05-21 10:10 ihge2k 阅读(719) 评论(0) 推荐(0)
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1544思路:枚举中间点,分为奇数长度和偶数长度,然后向两边扩展就可以了,如果不相等,就直接跳出; 1 #include 2 #include 3 #include 4 using namespace std; 5 #define MAXN 5005 6 char str[MAXN]; 7 8 int main(){ 9 while(~scanf("%s",&str)){10 int len=strlen(str),l,r;11 int ans=len;12 ... 阅读全文
posted @ 2013-05-20 23:54 ihge2k 阅读(1437) 评论(0) 推荐(1)
摘要: 题目链接:http://acm.upc.edu.cn/problem.php?cid=1028&pid=3刚刚做的比赛的一道dp题,感觉不错,就拿出来分享一下:思路://dp[i][j][k]表示前i个字符算出的值是j并且最后一位为k(0/1)的数的个数//dp[i][j][0]=dp[i-1][j][0]+dp[i-1][j][1];//dp[i][j][1]=dp[i-1][j-1][1]+dp[i-1][j][0];下面的就简单了。 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring& 阅读全文
posted @ 2013-05-20 22:24 ihge2k 阅读(246) 评论(0) 推荐(0)
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3468大牛思路:用BFS找出每一个集合点到其它可达点的距离以及这个集合点到下一集合点的距离枚举是否能从一个集合点K经过一个宝物点X到达下一个集合点(K+1).如果能的话,则path[K][X]=true;如果发现有一个集合点不可达的话,则输出-1; 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 #define MAXN 110 8 char map[MAXN][MAXN]... 阅读全文
posted @ 2013-05-20 19:01 ihge2k 阅读(243) 评论(0) 推荐(0)
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4549思路:大牛思路:简单推导下有, a, b, a^1*b^1, a^1*b^2 .... 可以知道a,b的幂满足Fib, 然后构造矩阵快速幂...就好了.还需要个性质: A^X = A^( X mod Eular(M) ) ( mod M ) .然后我就郁闷啦,自己的代码怎么都过不了,orz...一下是wa代码,哪个大神帮忙看看: 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 #define MOD 10 阅读全文
posted @ 2013-05-20 11:02 ihge2k 阅读(664) 评论(1) 推荐(0)
上一页 1 ··· 92 93 94 95 96 97 98 99 100 ··· 121 下一页