随笔分类 -  dp

摘要:题目:http://acm.hdu.edu.cn/showproblem.php?pid=1058st[i]=min{st[a]*2,st[b]*3,st[c]*5,st[d]*7}View Code 1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 using namespace std; 5 int main() 6 { 7 long int n; 8 long int st[5850]; 9 long int a=1,b=1,c=1,d=1,small,i;10 st[1]=1 阅读全文
posted @ 2012-10-25 17:43 琳&leen 阅读(132) 评论(0) 推荐(0)
摘要:题目:http://acm.hdu.edu.cn/showproblem.php?pid=1051View Code 1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 typedef struct node 7 { 8 int x,y; 9 int flag;10 }sut;11 bool cmp(sut a,sut b)12 {13 if(a.x!=b.x)14 return a. 阅读全文
posted @ 2012-10-25 16:46 琳&leen 阅读(204) 评论(0) 推荐(0)
摘要:题目:http://acm.hdu.edu.cn/showproblem.php?pid=1025View Code 1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #define maxn 500010 5 using namespace std; 6 int a[maxn]; 7 int b[maxn];//存储序列长度为len的第i小的数中最小的数 8 int dp[maxn]; 9 int chazhao(int x,int l,int r)//查找第i-1的长度序列中,结 阅读全文
posted @ 2012-10-19 21:13 琳&leen 阅读(130) 评论(0) 推荐(0)
摘要:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2430题意:大概是有n个柱子,每个的长度是1到h[i]任意一个整数,用一根绳子把这些柱子的顶端都连起来,使得绳子长度最长。View Code 1 #include <iostream> 2 #include<math.h> 3 #include<cstdio> 4 #include<cstring> 5 using namespace std; 6 int main() 7 { 8 double 阅读全文
posted @ 2012-08-27 19:46 琳&leen 阅读(118) 评论(0) 推荐(0)
摘要:【转】01背包问题动态规划详解转载自sunstar1989最终编辑中华复生母动态规划是用空间换时间的一种方法的抽象。其关键是发现子问题和记录其结果。然后利用这些结果减轻运算量。比如01背包问题。因为背包最大容量M未知。所以,我们的程序要从1到M一个一个的试。比如,开始任选N件物品的一个。看对应M的背包,能不能放进去,如果能放进去,并且还有多的空间,则,多出来的空间里能放N-1物品中的最大价值。怎么能保证总选择是最大价值呢?看下表。测试数据:10,33,44,55,6c[i][j]数组保存了1,2,3号物品依次选择后的最大价值.这个最大价值是怎么得来的呢?从背包容量为0开始,1号物品先试,0,1 阅读全文
posted @ 2012-08-11 18:37 琳&leen 阅读(550) 评论(0) 推荐(0)
摘要:题目:http://acm.hdu.edu.cn/showproblem.php?pid=1003代码:View Code 1 #include<stdio.h> 2 int a[100010]; 3 int main() 4 { 5 int t,n,i,k; 6 int thissum,maxsum,xt,x,yt; 7 scanf("%d",&t); 8 for(k=1;k<=t;k++) 9 {10 scanf("%d",&n);11 for(i=0;i<n;i++)12 {13 ... 阅读全文
posted @ 2012-08-10 17:03 琳&leen 阅读(115) 评论(0) 推荐(0)
摘要:题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1299代码:View Code 1 #include<stdio.h> 2 int main() 3 { 4 int n,i,j; 5 int a[1010],len[1010],max,maxlen=1; 6 scanf("%d",&n); 7 for(i=0;i<=9;i++) 8 len[i]=1; 9 for(i=0;i<n;i++)10 {11 scanf("%d.. 阅读全文
posted @ 2012-08-10 17:01 琳&leen 阅读(160) 评论(0) 推荐(0)
摘要:题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2080代码:View Code 1 #include<stdio.h> 2 #include<string.h> 3 int max(int a, int b) 4 { 5 if(a>b) 6 return a; 7 else 8 return b; 9 }10 int main()11 {12 int len1,len2,i,j;13 char str1[505],str2[505];14 ... 阅读全文
posted @ 2012-08-10 16:59 琳&leen 阅读(175) 评论(0) 推荐(0)
摘要:题目 :http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1730代码:View Code #include<stdio.h>int main(){ int n,i,j,dp[105][105]; scanf("%d",&n); for(i=0;i<n;i++) for(j=0;j<=i;j++) scanf("%d",&dp[i][j]); for(i=n-2;i>=0;i--) { for(j=0;j< 阅读全文
posted @ 2012-08-10 16:57 琳&leen 阅读(150) 评论(0) 推荐(0)
摘要:最大子序列和问题问题描述:输入一组整数,求出这组数字子序列和中最大值。也就是只要求出最大子序列的和,不必求出最大的那个序列。例如:序列:-2 11 -413 -5 -2,则最大子序列和为20。序列:-6 2 4 -7 5 3 2 -1 6 -9 10 -2,则最大子序列和为16。算法一://穷举法,复杂度O(n^3)long maxSubSum1(const vector<int>& a){ long maxSum = 0; for (int i = 0; i < a.size(); i++) { for (int j = i; j < a.size(); j+ 阅读全文
posted @ 2012-08-10 16:53 琳&leen 阅读(150) 评论(0) 推荐(0)