[CF98E]Help Shrek and Donkey(纳什均衡)

https://www.cnblogs.com/MashiroSky/p/6576398.html

 1 #include<cstdio>
 2 #include<algorithm>
 3 #define rep(i,l,r) for (int i=(l); i<=(r); i++)
 4 using namespace std;
 5 
 6 const int N=1010;
 7 int n,m;
 8 double g[N][N];
 9 
10 double f(int n,int m){
11     if (!n) return 1./(m+1);
12     if (!m) return 1.;
13     if (g[n][m]) return g[n][m];
14     double A=(1-(f(m-1,n)))*m/(m+1),B=(1-f(m-1,n))*m/(m+1)+1./(m+1);
15     double C=1-f(m,n-1),p=(C-1)/(A-B+C-1);
16     return g[n][m]=p*A+(1-p);
17 }
18 
19 int main(){
20     freopen("CF98E.in","r",stdin);
21     freopen("CF98E.out","w",stdout);
22     scanf("%d%d",&n,&m); printf("%.10lf %.10lf\n",f(n,m),1-f(n,m));
23     return 0;
24 }

 

posted @ 2019-03-14 08:55  HocRiser  阅读(426)  评论(0编辑  收藏  举报