[NOIP Simulation Test]: Janken (RPS) (probability DP)

Topic Portal (internal question 9)


Input Format

A first line integer $ n $. Next, n-$ $ $ $ 3 lines each nonnegative integer $ r_i, p_i, s_i $.


Output Format

Line represents a real number answer. When the absolute or relative error does not exceed $ ^ {10} your answer with the standard answer {- 9} $ when the sentence is correct.


Sample

Sample input:

3
300 0 0
0 300 0
0 0 300

Sample output:

6.333333333333


Data range and tips

For the data of $ 10% $, $ n = 1 $.
For the data of $ 30% $, $ n \ leqslant 10 $.
Further data for $ $ 10% of all $ $ r_i are equal, all $ $ P_i are equal.
For yet another $ $ 30% of the data, $ r_i = 0 $.
For the data of $ 100% $, $ 1 \ leqslant n \ leqslant 50 $, $ r_i + p_i + s_i = 300 $.


answer

First of all, this question is a false expectation.

With $ g [i] [j] [k] $ denotes $ i + j + k $ I $ $ a round stones, the probability of scissor $ J $, $ a $ K cloth.

With $ dp [i] [j] [k] [l] $ represents the front $ i + j + k $ round a $ I $ stones, the probability of $ $ scissor J, K $ $ a cloth.

Note that we are not at $ dp [i] [j] [k] [x] $ fetch $ \ max $, but $ dp [i] [j] [k] [x] + dp [i] [j ] [k] [x + 1] \ times 3 $ fetch $ \ max $.

$ G [i] [j] [k] $ find also very good, directly using equation: $ g [i] [j] [k] = g [i-1] [j] [k] \ times r [t] + g [i] [j-1] [k] \ times s [t] + g [i] [j] [k-1] \ times p [t] $.

Note that $ dp $ and $ g $ significance, so the transfer of $ g $ is required after the $ dp $.

There is a note input sequence is: stone, cloth, scissors, you can.

Time complexity: $ \ Theta (n ^ 4) $.

Desired points: $ 100 $ points.

The actual sub-: $ 100 $ points.


Code time

#include<bits/stdc++.h>
using namespace std;
int n;
long double w[100],z[100],c[100];
long double C[51][51];
long double g[51][51][51],dp1[51][51][51],dp2[51][51][51],dp3[51][51][51];
long double ans;
int main()
{
	scanf("%d",&n);
	for(int i=0;i<=n;i++)
	{
		C[i][0]=1.0;
		for(int j=1;j<=i;j++)
			C[i][j]=C[i-1][j]+C[i-1][j-1];
	}
	for(int i=1;i<=n;i++)
	{
		cin>>w[i]>>c[i]>>z[i];//注意输入顺序
		w[i]/=300.0;
		z[i]/=300.0;
		c[i]/=300.0;
	}
	g[0][0][0]=1.0;
	for(int t=1;t<=n;t++)
		for(int i=t;~i;i--)
			for(int j=t-i;~j;j--)
				for(int k=t-i-j;~k;k--)
				{
					if(i+j+k!=t)
					{
						if(i)dp1[i][j][k]+=dp1[i-1][j][k]*w[t];
						if(j)dp1[i][j][k]+=dp1[i][j-1][k]*z[t];
						if(k)dp1[i][j][k]+=dp1[i][j][k-1]*c[t];
						dp1[i][j][k]+=g[i][j][k]*w[t];
						if(i)dp2[i][j][k]+=dp2[i-1][j][k]*w[t];
						if(j)dp2[i][j][k]+=dp2[i][j-1][k]*z[t];
						if(k)dp2[i][j][k]+=dp2[i][j][k-1]*c[t];
						dp2[i][j][k]+=g[i][j][k]*z[t];
						if(i)dp3[i][j][k]+=dp3[i-1][j][k]*w[t];
						if(j)dp3[i][j][k]+=dp3[i][j-1][k]*z[t];
						if(k)dp3[i][j][k]+=dp3[i][j][k-1]*c[t];
						dp3[i][j][k]+=g[i][j][k]*c[t];
					}
					if(i)g[i][j][k]+=g[i-1][j][k]*w[t];
					if(j)g[i][j][k]+=g[i][j-1][k]*z[t];
					if(k)g[i][j][k]+=g[i][j][k-1]*c[t];
				}
	for(int i=0;i<n;i++)
		for(int j=0;i+j<n;j++)
			for(int k=0;i+j+k<n;k++)
				ans+=max(dp1[i][j][k]+3.0*dp2[i][j][k],max(dp2[i][j][k]+3.0*dp3[i][j][k],dp3[i][j][k]+3.0*dp1[i][j][k]))/(C[n][i+j+k]*(n-i-j-k));
	cout<<fixed<<setprecision(12)<<ans<<endl;
	return 0;
}

rp ++

Guess you like

Origin www.cnblogs.com/wzc521/p/11331681.html