UVA - 11021 - Tribles
题目传送:Tribles
AC代码:
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <sstream>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>
#define LL long long
#define INF 0x7fffffff
using namespace std;
int N;
int n, k, m;
//因为每只麻球都相互独立,所以只要先求一只麻球的即可
double P[1005];//P[i]代表一只麻球生出i只麻球的概率
double f[1005];//f[i]代表每一只麻球以及他的后代i天后全部死亡的概率,则答案为f[m]^k
int main() {
scanf("%d", &N);
for(int cas = 1; cas <= N; cas ++) {
scanf("%d %d %d", &n, &k, &m);
for(int i = 0; i < n; i ++) {
scanf("%lf", &P[i]);
}
f[0] = 0;
f[1] = P[0];
for(int i = 2; i <= m; i ++) {
f[i] = 0;
for(int j = 0; j < n; j ++) f[i] += P[j] * pow(f[i-1], j);
}
printf("Case #%d: %.7lf\n", cas, pow(f[m], k));
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-11-07 19:30:04