序列最的问题之最长公共子序列LCS
摘要:在程序设计竞赛中,我们时常会遇到序列求最值的问题。在讲今天的问题之前,先小小的说明一下,子序列与子串的问题。 子序列:在原序列中不一定连续; 子串:在原序列中必须连续。 接下来,就开始今天要讲的最长公共子序列LCS(Longest Common Subsequence).对于LCS这一类的...
阅读全文
hdu 1248 寒冰王座(动态)
摘要:题意:最多能买多少东西。完全背包。连接:http://acm.hdu.edu.cn/search.php?action=listproblemView Code #include <iostream>using namespace std;const int MAX=10000+10;int w[5];int dp[MAX];int cmp(int a,int b){ return a>b?a:b;}int main(){ int n,m; w[1]=150,w[2]=200,w[3]=350; while(~scanf("%d",&m)) { w
阅读全文
hdu 1203 I NEED A OFFER!(动态0-1背包)
摘要:题意:求被录取的概率连接:http://acm.hdu.edu.cn/showproblem.php?pid=1203View Code #include <iostream>using namespace std;const int MAX=10000+10;int v[MAX];double w[MAX];double dp[MAX];double cmp(double a,double b){ return a>b?a:b;}int main(){ int n,m; while(scanf("%d%d",&n,&m),n+m) { m
阅读全文
hdu 2602 Bone Collector(动态)
摘要:题意:给出一组价值的数据,再给出一组体积的数据。求在m体积下所放的物品价值最大价值。连接:http://acm.hdu.edu.cn/showproblem.php?pid=2602View Code #include <iostream>using namespace std;const int MAX=1000+10;int v[MAX];int w[MAX];int dp[MAX];int cmp(int a,int b){ return a>b?a:b;}int main(){ int k; while(~scanf("%d",&k)) {
阅读全文
hdu 1087 Super Jumping! Jumping! Jumping!(简单动态)
摘要:题意:求出最大子序列和解题思路:i12345map[i]14235sum[i]153611定义一个map数组保存所输入的数据,sum数组保存到达此点的最大值(采用松弛操作),在用max找最大值。注意:可能全为负数。我坑了3次。连接:http://acm.hdu.edu.cn/showproblem.php?pid=1087View Code #include <iostream>using namespace std;int main(){ int n; while(scanf("%d",&n),n) { int sum[1100]; in...
阅读全文