XJOI网上同步训练DAY6 T2
思路:记得FJ省队集训好像有过这题,可是我太弱了,根本不懂T_T
1 #include<cstdio> 2 #include<iostream> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 int n,m; 7 double f[1005][1005]; 8 int pd[1005][1005]; 9 int read(){ 10 int t=0,f=1;char ch=getchar(); 11 while (ch<'0'||ch>'9'){if (ch=='-')f=-1;ch=getchar();} 12 while ('0'<=ch&&ch<='9'){t=t*10+ch-'0';ch=getchar();} 13 return t*f; 14 } 15 void dfs(int n,int m){ 16 if (pd[n][m]) return; 17 pd[n][m]=1; 18 if (n==0||m==0) f[n][m]=(1.0)/(m+1);else{ 19 dfs(m-1,n);dfs(m,n-1); 20 double x,y,x1,y1; 21 x=m/(m+1.0)*(1-f[m-1][n])-1,y=1; 22 x1=m/(m+1.0)*(1-f[m-1][n])+1.0/(m+1)+(f[m][n-1]-1); 23 y1=1-f[m][n-1]; 24 double a=(y1-y)/(x-x1); 25 f[n][m]=a*x1+y1; 26 } 27 } 28 int main(){ 29 n=read();m=read(); 30 dfs(n,m); 31 printf("%.10f %.10f\n",f[n][m],1-f[n][m]); 32 }