随笔分类 -  ACM~背包

摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1203一个简单的0-1背包问题 特别之处就是算的是概率 是乘法的操作 所以把原来的加法用函数代替为相应的操作即可#include<iostream>#include<stdio.h>#include<cstring>using namespace std;int m;double dp[10001];double f(double x,double y){ return 1-(1-x)*(1-y);}void ZeroOnePack(int cost, double wei 阅读全文
posted @ 2011-07-30 16:38 Crazy_yiner 阅读(234) 评论(0) 推荐(0)
摘要:0-1 背包有N件物品和一个容量为m的背包。第i件物品的费用是c[i],价值是w[i]。求解将哪些物品装入背包可使价值总和最大。特点:每种物品仅有一件,可以选择放或不放。void ZeroOnePack(int cost, int weight){ for (int i = m; i >= cost; i--) dp[i] = max(dp[i], dp[i-cost] + weight);}完全背包有N种物品和一个容量为V的背包,每种物品都有无限件可用。第i种物品的费用是c[i],价值是w[i]。求解将哪些物品装入背包可使这些物品的费用总和不超过背包容量,且价值总和最大。特点:每种物品 阅读全文
posted @ 2011-05-26 16:25 Crazy_yiner 阅读(345) 评论(0) 推荐(0)
摘要:#include<iostream>#include<stdio.h>#include<cstring>using namespace std;int a[101],c[101];int num[100001],f[100001];int main(){int n,m;while(scanf("%d %d",&n,&m)!=EOF){if(n==0&&m==0)break;int sum=0;for(int i=1;i<=n;i++)scanf("%d",&a[i]);fo 阅读全文
posted @ 2011-05-16 23:28 Crazy_yiner 阅读(158) 评论(0) 推荐(0)
摘要:/**********************************有一定的钱 存在银行里给出可存的钱数 和相应利息第一年的利息会加入到第二年的本金中***********************************/#include<iostream>#include<stdio.h>#include<cstring>using namespace std;int d[50000],v[12],w[12];//数组开大了会超时int main(){ int n; //freopen("out.txt","w", 阅读全文
posted @ 2011-05-16 23:27 Crazy_yiner 阅读(225) 评论(0) 推荐(0)