题目链接:哆啦A梦传送门
题意:有n个题目,每个题目1个正确选项bi个错误的,让我们选择一个最大子集S使得有人可以将这S个题全做对,人数不超过m个。
题解:答对一道题的概率为 ,所需最少人数为(1+b)人,答对两道题的概率,所需最少人数为(1+b1)(1+b2)。
代码:
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int ans[200];
int main()
{
int ncase;
scanf("%d",&ncase);
while(ncase--)
{
int a,b,n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++){
scanf("%d%d",&a,&b);
ans[i]=a+b;
}
sort(ans+1,ans+1+n);
int t;
long long sum=1;
for( t=1;t<=n;t++)
{
sum*=ans[t];
if(sum>m){
break;
}
}
printf("%d\n",t-1);
}
return 0;
}