java - codesprint2 programming contest answer
<p>I recently took part in Codesprint2. I was unable to submit the solution to the following question.
<a href="http://www.spoj.pl/problems/COINTOSS/" rel="nofollow">http://www.spoj.pl/problems/COINTOSS/</a>
( I have posted the link to the problem statement at spoj because the codesprint link requires login )</p>

<p>I checked out one of the successful solutions, ( url : <a href="http://pastebin.com/uQhNh9Rc" rel="nofollow">http://pastebin.com/uQhNh9Rc</a> ) and the logic used is exactly the same as mine, yet I am still getting "Wrong Answer"</p>

<p>I would be very thankful if someone could please tell me what error I have made, as I am unable to find it. Thank you.</p>

<p>My code : </p>

<pre><code>import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.DecimalFormat;
import java.util.StringTokenizer;


public class Solution
{

static double solve( int n, int m )
{
    if( m==n )
        return 0;

    if( m==0 )
        return ( Math.pow( 2, n+1 ) - 2 );

    else
    {
        double res = 1 + ( Double )(  solve( n, m+1 ) + solve( n, 0 ))/2;
        return res;
    }
    }


public static void main( String[] args ) throws IOException
{

BufferedReader br = new BufferedReader( new InputStreamReader( System.in ));
int n, m;

int t = Integer.parseInt( br.readLine() );
StringTokenizer tok;
String s;

for( int T=0; T&lt;t; T++ )
{
    s = br.readLine();
    tok = new StringTokenizer( s );

    n = Integer.parseInt( tok.nextToken() );
    m = Integer.parseInt( tok.nextToken() );

    DecimalFormat df = new DecimalFormat();
    df.setMaximumFractionDigits(2);
    df.setMinimumFractionDigits(2);

    System.out.println( df.format ( solve( n, m ) ));
}


}
</code></pre>

<p>}</p>
