hdu 4815 Little Tiger vs. Deep Monkey

概率dp,有点像背包的做法;

dp[i][j]代表前i个数组成的j数的概率为多少

#include<cstdio>
#include<cstring>
#define maxn 40009
using namespace std;

double dp[45][maxn];
int s;
double sco;

int main()
{
    int t,n;
    scanf("%d",&t);
    while(t--)
    {
        memset(dp,0,sizeof dp);
        dp[0][0]=1;
        scanf("%d%lf",&n,&sco);
        for(int i=0;i<n;i++)
        {
            scanf("%d",&s);
            for(int j=0;j<40000;j++)
            {
                dp[i+1][j]+=dp[i][j]*0.5;
                dp[i+1][j+s]+=dp[i][j]*0.5;
            }
        }
        double ans=0;
        int tmp=0;
        for(int i=0;i<40000;i++)
        {
            ans+=dp[n][i];
            if(ans>=sco)
                {tmp=i;break;}
        }
        printf("%d\n",tmp);
    }
    return 0;
}
View Code

 

posted @ 2014-02-19 08:27  Yours1103  阅读(180)  评论(0编辑  收藏  举报