题目:
分析:
通过这次题目,告诉我们:做期望的题目千万不能看样例
抛开样例,我们考虑到
n
,
k
<
=
9
n,k<=9
n,k<=9,所以果断用两次暴力,第一次枚举出如何分发糖果,第二次模拟出每个议员是投出赞成票还是反对票,以及通过暗杀所有反对议员使得方案成功的概率
代码:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<ctime>
#include<iomanip>
#include<string>
#include<bitset>
#include<deque>
#include<set>
#define LL long long
using namespace std;
inline LL read(){
LL d=0,f=1;char s=getchar();
while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
while(s>='0'&&s<='9'){d=d*10+s-'0';s=getchar();}
return d*f;
}
double ans,king;
int a[15],n,w; double b[15];
void check(int i,int num,int s,double k)
{
if(k==0) return;
if(i>n)
{
if(num>n/2) king+=k;
else king+=k*(double)w/(w+s);
return;
}
check(i+1,num+1,s,k*b[i]);
check(i+1,num,s+a[i],k*(1-b[i]));
return;
}
void dfs(int num,int k)
{
if(k==0) {
king=0;check(1,0,0,1);ans=max(ans,king);return;}
if(num>n) return;
for(int i=0;i<=k;i++)
{
if(b[num]+0.1*i>1.000001) break;
b[num]+=0.1*i;
dfs(num+1,k-i);
b[num]-=0.1*i;
}
return;
}
int main()
{
n=read();int k=read();w=read();
for(int i=1;i<=n;i++) a[i]=read(),b[i]=(double)read()/100;
ans=0;
dfs(1,k);
printf("%.6lf",ans);
return 0;
}