poj 2151 01背包

来源:互联网 发布:中国gdp数据折线图 编辑:程序博客网 时间:2024/06/05 05:05

在别人列出的题目里面这道题是被归类到hash里面的,然而没有想到如何转化成hash搜索

这道题就是求出   Π每队至少解出一道题= Π(1-每队解出0道题的概率)=P1, Π每队解出不多于n道题的概率 =P2

注意的是P2 不包括解出0道的概率

#include<iostream>  #include<vector>#include <string>   #include<algorithm>  #include<fstream>#include<cmath>  using namespace std;  #define lch(i) ((i)<<1)  #define rch(i) ((i)<<1|1)  #define sqr(i) ((i)*(i))  #define pii pair<int,int>  #define mp make_pair  #define FOR(i,b,e) for(int i=b;i<=e;i++)  #define FORE(i,b,e) for(int i=b;i>=e;i--)  #define ms(a)   memset(a,0,sizeof(a))  const int maxnum =20010;const int key = 177;int tol,n,t,m,newn;double dp[1005];int main()    {    /*fstream fin("G:/1.txt");*/while (scanf("%d%d%d", &m, &t, &n), n | t | m){/*fin>>m>>t>>n;*/double one=1.0,below=1.0;double tmp;FOR(i,1,t){ms(dp);dp[0]=1;FOR(j,1,m){/*fin>>tmp;*/scanf("%lf",&tmp);FORE(k,t,1){dp[k]=dp[k]*(1-tmp)+dp[k-1]*tmp;}dp[0]=dp[0]*(1-tmp);}one*=1-dp[0];double sum=0;FOR(j,1,n-1){sum+=dp[j]; }below*=sum;}printf("%.3f\n",one-below);}return 0;}  


0 0