Fisa Flood (UVA 13052) by return_zukky
Contest: 3738    RunID: 20174760    Status: Time limit exceeded    Date: Sat Oct 14 17:11:55 JST 2017


#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
double dp[2005][2005];
int main(){
  int n,a,b;
  cin>>n;
  r(i,n){
    memset(dp,0,sizeof(dp));
    cout<<"Case "<<i+1<<": ";
    cin>>a>>b;
    dp[a][b]=1;
    for(int j=b;j>=0;j--){

      for(int i=2000;i>=0;i--)if(dp[i][j]){

	  int cnt=0;

	  if(i>=1&&j>=1)cnt++;
	  if(i>1)cnt++;
	  if(j>1)cnt++;

	  if(!cnt)continue;

	  if(i>=1&&j>=1)dp[i-1][j]+=dp[i][j]/cnt;
	  if(i>1)dp[i-1][j]+=dp[i][j]/cnt;
	  if(j>1)dp[i+1][j-2]+=dp[i][j]/cnt;
      }
    }
    double ans=0;
    //cout  << dp[1][0] << endl;
    ans=dp[1][0];

    printf("%.5f %.5f\n",ans,1.0-ans);
  }
}