HDOJ1203(01背包 概率)

本文通过使用C++实现了一个动态规划算法来解决一类背包问题。该算法能够在每次迭代中更新状态,以找到最大价值的解决方案。通过对物品是否加入背包进行概率性的评估,实现了对背包容量的有效利用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include <iostream>   
#include <cstring>  
#include <string>  
#include <cstdio>  
#include <algorithm>  
#include <stack>  
#include <math.h>  
#include<iostream>  
#include <map>  

using namespace std;
#define INF  0xfffff;//0x代表十六进制  
#define M 10050  

double dp[M];

int main()
{
int mon, n;
while (cin >> mon >> n, mon+n)  //之前写mon,n一直没事啊~ 为毛???
{
memset(dp, 0, sizeof(dp));
for (int i = 0; i < n; i++)
{
int a;
double b;
cin >> a >> b;
for (int j = mon; j >= a; j--)
{
dp[j] = max(dp[j], 1-(1-dp[j - a]) * (1-b));
}
}
printf("%.1lf%%\n",dp[mon]*100);
}
return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值