英文有点虐,The test is composed of N binary choice questions应该是概率对半的意思。
what score should I get at least so that I will not lose in the contest with probability of at least P?
至少得多少分以至于不输的概率至少是p。
这里不加exp也能过,不过习惯加了。
#include<stdio.h>
#include<string.h>
const double exp=1e-6;
int a[42];
double dp[42][42000];
int main(){
int n,tt;
double p;
scanf("%d",&tt);
while(tt--){
memset(dp,0,sizeof dp);
scanf("%d %lf",&n,&p);
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
int mx=n*1000;
dp[0][0]=1;
for(int i=0;i<n;i++){
for(int j=0;j<=mx;j++){
if(dp[i][j]==0) continue;
dp[i+1][j+a[i]]+=dp[i][j]*0.5;
dp[i+1][j]+=dp[i][j]*0.5;
}
}
int val;
double ans=0;
for(int i=0;i<=mx;i++){//得i分的概率
ans+=dp[n][i];
if(ans+exp>=p){//小于的都是要输的
val=i;break;
}
}
printf("%d\n",val);
}
return 0;
}