摘要:
http://acm.hdu.edu.cn/showproblem.php?pid=2955费用为实数的背包问题,可以考虑把费用和价值换一换,把价值看成费用,费用看成价值。其实就是算构成某一种价值的最小(或最大)费用。我的代码 1 #include <stdio.h> 2 #include <string.h> 3 const int V=10010; 4 double f[V],p[110]; 5 int m[110]; 6 int main() 7 { 8 int T,i,j,n,v; 9 double pp;10 scanf("%d",&
阅读全文
posted @ 2011-12-12 16:45
Qiuqiqiu
阅读(181)
推荐(0)
摘要:
http://acm.hdu.edu.cn/showproblem.php?pid=3466直接01背包肯定WA,按q排了下序,还是WA,查了一下是按q-p排序,不知道为什么可能是因为 for (j=n;j>=q;j--) f[j]>?=f[j-p]+w; 先算q-p最小的,而不是q最小的我的代码 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 const int N=510,M=5010; 5 struct item 6 { 7 int p,q,v; 8 }a
阅读全文
posted @ 2011-12-12 15:22
Qiuqiqiu
阅读(214)
推荐(0)
摘要:
http://acm.hdu.edu.cn/showproblem.php?pid=3496二维费用的01背包问题,其中一维费用必须装满,赋初值为负无穷打,另一维不用装满,赋初值为0我的代码 1 #include <stdio.h> 2 #include <string.h> 3 const int N=110,INF=0x3fffffff; 4 int f[N][1010],c[N],w[N]; 5 int main() 6 { 7 int T,m,n,l,i,j,k; 8 scanf("%d",&T); 9 while (T--)10 {
阅读全文
posted @ 2011-12-12 13:40
Qiuqiqiu
阅读(217)
推荐(0)
摘要:
http://acm.hdu.edu.cn/showproblem.php?pid=2844背包问题我的代码 1 #include <stdio.h> 2 #include <string.h> 3 const int M=100010,N=1010;; 4 int f[M],a[N],c[N]; 5 int main() 6 { 7 int n,m,i,j,k,cc; 8 while (scanf("%d%d",&n,&m) && (n||m)) 9 {10 for (i=1;i<=n;i++) scanf(&
阅读全文
posted @ 2011-12-12 13:07
Qiuqiqiu
阅读(147)
推荐(0)