Passage
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 411 Accepted Submission(s): 192
We already know that Bill has M million dollars. Help Bill to find out the probability that he can escape from this castle if he chose the optimal strategy.
The first line of each test case contains two integers n (1<=n<=1000) and M (0<=M<=10).
Then n lines follows, each line contains two float number Pi and Qi.
The answer should be rounded to five digits after the decimal point.
Follow the format of the sample output.
3 1 10 0.5 0 2 0 0.3 0.4 0.4 0.5 3 0 0.333 0.234 0.353 0.453 0.342 0.532
Case 1: 0.50000 Case 2: 0.43000 Case 3: 0.51458
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn = 1000 + 10;
struct node
{
double p,q;
void read(){
scanf("%lf%lf",&p,&q);
}
bool operator < (const node &B) const{
return p / (p + q) > B.p / (B.p + B.q);
}
}pa[maxn];
double dp[1005][15];
int main()
{
int T;
scanf("%d",&T);
int kase = 0;
while(T--){
int n,m;
scanf("%d%d",&n,&m);
for (int i = 0; i < n; i++)
pa[i].read();
sort(pa, pa + n);
memset(dp, 0, sizeof(dp));
for(int i = n - 1; i >= 0; i--){
for(int j = 0; j <= m; j++){
dp[i][j] = pa[i].p;
if(i + 1 < n && j - 1 >= 0) dp[i][j] += dp[i + 1][j - 1] * pa[i].q;
if(i + 1 < n) dp[i][j] += (1 - pa[i].p - pa[i].q) * dp[i + 1][j];
}
}
printf("Case %d: %.5lf\n",++kase, dp[0][m]);
}
}
948



被折叠的 条评论
为什么被折叠?



