记录编号 161220 评测结果 AAAAAAAAAA
题目名称 [HNOI 2015]亚瑟王 最终得分 100
用户昵称 GravatarAsm.Def 是否通过 通过
代码语言 C++ 运行时间 0.473 s
提交时间 2015-05-02 18:09:13 内存使用 0.75 MiB
显示代码纯文本
/***********************************************************************/
/**********************By Asm.Def-Wu Jiaxin*****************************/
/***********************************************************************/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <algorithm>
using namespace std;
#define SetFile(x) ( freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout) );
//#define UseFREAD
#ifdef UseFREAD
#define getc() *(file_ptr++)
#define FreadLenth 5000000
char CHARPOOL[FreadLenth], *file_ptr = CHARPOOL;
#else
#define getc() getchar() 
#endif
#ifdef DEBUG
#include <ctime>
#endif
template<class T>inline void getd(T &x){
	char ch = getc();bool neg = false;
	while(!isdigit(ch) && ch != '-')ch = getc();
	if(ch == '-')ch = getc(), neg = true;
	x = ch - '0';
	while(isdigit(ch = getc()))x = x * 10 - '0' + ch;
	if(neg)x = -x;
}
/***********************************************************************/
const int maxn = 222, maxr = 133;
const double eps = 1e-11;
double P[maxn], F[maxn][maxr], Pow[maxn][maxr];
int val[maxn];
inline void work(){
	memset(F, 0, sizeof(F));
	int i, j, n, r;
	double Ans = 0;
	getd(n), getd(r);
	for(i = 1;i <= n;++i)scanf("%lf", P + i), getd(val[i]);
	for(i = 1;i <= n;++i)P[i] = 1.0 - P[i];
	for(i = 1;i <= n;++i){
		Pow[i][0] = 1.0;
		for(j = 1;j <= r;++j)Pow[i][j] = Pow[i][j-1] * P[i];
	}
	Ans += val[1] * (1 - Pow[1][r]) * (F[1][r] = 1.0);
	for(i = 2;i <= n;++i){
		for(j = 0;j <= r;++j)
			Ans += val[i] * (1 - Pow[i][j]) * (F[i][j] = F[i-1][j] * Pow[i-1][j] + F[i-1][j+1] * (1 - Pow[i-1][j+1]));
	}

	printf("%.10lf\n", Ans);
}

int main(){

#ifdef DEBUG
	freopen("test.txt", "r", stdin);
#elif !defined ONLINE_JUDGE
	SetFile(arthur);
#endif

#ifdef UseFREAD
	fread(file_ptr, 1, FreadLenth, stdin);
#endif
	
	int T;
	getd(T);
	while(T--)work();

#ifdef DEBUG
	printf("\n%.3lf sec \n", (double)clock() / CLOCKS_PER_SEC);
#endif
	return 0;
}