HDU 4815 背包

标题的含义给出N问题。和概率P,然后给予相应的分数为每个问题x(每个问题只有两种选择,纠正错误)。

两个人来回答。一个人是随机选择的答案,问:还有一个人的至少一些点的能力有保证P概率不会失败。

01背包,最大分数为40000,01背包处理,记录这40000个分数出现的次数

然后从小分数遍历一边就可以


#include "stdio.h"
#include "string.h"
#include "math.h"
__int64  hash[40010];

__int64 fuck(double x)
{
    if(x-(int)x<=0.0000001) return  (int)x;
    return (int)x+1;
}

int main()
{
    __int64 Case,n,i,j,x,sum;
    double temp,p,key;
    scanf("%I64d",&Case);
    while (Case--)
    {
        scanf("%I64d%lf",&n,&p);

        temp=pow(2.0,n*1.0)*1.0;

        memset(hash,0,sizeof(hash));

        hash[0]=1;
        for (i=1;i<=n;i++)
        {
            scanf("%I64d",&x);
            for (j=40000-x;j>=0;j--)
                if(hash[j]!=0)
                    hash[j+x]+=hash[j];
        }
        sum=0;
        for (i=0;i<=40000;i++)
            if(hash[i]!=0)
            {
                sum+=hash[i];
                key=sum/temp;
                if (key>=p) break;
            }

        printf("%I64d\n",i);
    }
    return 0;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

时间: 2024-08-26 09:35:30

HDU 4815 背包的相关文章

HDU 4815 2013长春现场赛C题

C - Little Tiger vs. Deep Monkey Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4815 Description A crowd of little animals is visiting a mysterious laboratory ? The Deep Lab of SYSU. "Are y

hdu 4381 背包

http://acm.hdu.edu.cn/showproblem.php?pid=4381 Problem Description There are n boxes in one line numbered 1 to n, at the beginning, all boxes are black. Two kinds of operations are provided to you: 1 ai xi :You can choose any xi black boxes in interv

hdu 4815 Little Tiger vs. Deep Monkey(01背包)

http://acm.hdu.edu.cn/showproblem.php?pid=4815 Description A crowd of little animals is visiting a mysterious laboratory ? The Deep Lab of SYSU. “Are you surprised by the STS (speech to speech) technology of Microsoft Research and the cat face recogn

HDU 4815 Little Tiger vs. Deep Monkey 背包问题

链接:http://acm.hdu.edu.cn/showproblem.php?pid=4815 题意:很"内涵"的一个题面,题意是给出N道题,和一个概率P,然后给出每道题对应的得分aa[i](每道题只有两个选项,一个正确一个错误).两个人来答题,一个人是随机选择答案,问另一个人至少要答多少分才能保证有P的概率不会失败. 思路:是一道DP题,最开始想强行枚举所有情况,找到需要分数,后来发现40道题强行枚举2^40必然超时,思路就中断了,后来想到DP,刚开始DP的可能得到的分数,但是很

HDU-1171 Big Event in HDU (多重背包)

Problem Description Nowadays, we all know that Computer College is the biggest department in HDU. But, maybe you don't know that Computer College had ever been split into Computer College and Software College in 2002.The splitting is absolutely a big

poj 3624 &amp;&amp; hdu 2955(背包入门)

http://poj.org/problem?id=3624 背包中最基础的01背包,大意是有N件物品和一个容量为V的背包.第i件物品的费用是c[i],价值是w[i].求解将哪些物品装入背包可使价值总和最大 主要是要有动态规划的思想,列出每个容量下的最大值,每次只考虑取或不取两种情况<一个状态一个状态的转移 1 #include<iostream> 2 #include<cstring> 3 using namespace std; 4 int dp[12900]; 5 in

HDU 4815 Little Tiger vs. Deep Monkey

http://acm.hdu.edu.cn/showproblem.php?pid=4815 题意: 给定N个题目各自的分数a[i] A有50%的概率答对一道题目得到相应分数,B想要在至少P的概率上总分不低于A 问B至少要得到多少分 解法: 概率DP dp[i][j]表示前i题得到j分的概率 递推式: dp[i][j] = dp[i-1][j] * 0.5 (a[i]>j) dp[i][j] = (dp[i-1][j] + dp[i-1][j - a[i]]) * 0.5 (a[i]<=j)

HDU 1171 Big Event in HDU(01背包)

题目地址:HDU 1171 还是水题..普通的01背包.注意数组要开大点啊.... 代码如下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #include <ctype.h> #include <queue> #include &

HDU 2639 背包第k优解

Bone Collector II Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4824    Accepted Submission(s): 2514 Problem Description The title of this problem is familiar,isn't it?yeah,if you had took par