Fisa Flood (UVA 13052) by return_zukky
Contest: 3738    RunID: 20174817    Status: Accepted    Date: Sat Oct 14 17:20:18 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-=2){

      for(int i=a+b/2+10;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;
      }
    }

    printf("%.3f %.3f\n",dp[1][0],dp[0][1]);
  }
}