Fisa Flood (UVA 13052) by UKUNICHIA
Contest: 3738    RunID: 20173958    Status: Time limit exceeded    Date: Sat Oct 14 14:51:47 JST 2017


#include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){
  int T;
  cin>>T;
  for(int t=1;t<=T;t++){
    cout<<"Case "<<t<<": ";
    static double dp[2000][2000];
    for(int i=0;i<2000;i++)
      for(int j=0;j<2000;j++)
	dp[i][j]=0;
    int sum;
    {
      int a,b;
      cin>>a>>b;
      dp[a][b]=1.0;
      sum=a+b;
    }
    for(int i=sum;i>1;i--){
      for(int j=0;j<=i;j++){

	for(int a=0;a<2;a++){
	  for(int b=0;b<2;b++){
	    int x=j,y=i-j;
	    double p=1.0;
	    if(a){
	      if(!x) continue;
	      p*=((double)x)/(x+y);
	      x--;
	    }else{
	      if(!y) continue;
	      p*=((double)y)/(x+y);
	      y--;
	    }
	    if(b){
	      if(!x) continue;
	      p*=((double)x)/(x+y);
	      x--;
	    }else{
	      if(!y) continue;
	      p*=((double)y)/(x+y);
	      y--;
	    }
	    if(a^b) dp[x][y+1]+=dp[j][i-j]*p;
	    else    dp[x+1][y]+=dp[j][i-j]*p;
	  }
	}
      }
    }

    cout<<fixed<<setprecision(3)<<dp[1][0]<<" "<<dp[0][1]<<endl;
  }

  return 0;
}