1. Java

/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS10
* Problem: 10811 - Up the Ante
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=20&problem=1752&mosmsg=Submission+received+with+ID+8022978
*
* @author Evgeni Pavlidis
* @version 1.0, 06/07/2010
*
* Method : Recursion & Memoization
* Status : Accepted
* Runtime: 0.632
*/

import java.io.*;
import java.util.*;

class Main {

private static int k,m,l;
private static Map<Long, Double> cache = new HashMap<Long, Double>();


private static double f(long r, long b, long p) // round, bet, profit
{
if(cache.containsKey((r << 50) + (b << 32) + p))
return cache.get((r << 50) + (b << 32) + p);

// stan wins...
if(r > k && p > 0)
return 1.0;

// break recursion at m
if(r > m)
return 0.0;

// reset bet if it exceeds limit
if((1 << b) > l)
b = 0;

// recurse into all possibilities
double sum = 0;
sum += 20.0/28.0 * f(r+1, b+1, p - (1 << b)); // stan looses
sum += 4.0 /28.0 * f(r+1, 0 , p + (1 << b)); // stan hits once
sum += 2.0 /28.0 * f(r+1, 0 , p + (1 << b)*2); // stan hits twice
sum += 2.0 /28.0 * f(r+1, 0 , p + (1 << b)*3); // stan hits triple

cache.put((r << 50) + (b << 32) + p, sum);

return sum;
}

public static void main(String...args)
{
Scanner sc = new Scanner(System.in);

int testCases = sc.nextInt();
for(int tc = 0; tc < testCases; tc++)
{
cache.clear();
k = sc.nextInt();
m = sc.nextInt();
l = sc.nextInt();

System.out.printf("%.4f\n",f(1,0,0));
}
}
}

2. C++

/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS10
* Problem: 10811 - Up the Ante
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=20&problem=1752&mosmsg=Submission+received+with+ID+8022978
*
* @author Evgeni Pavlidis
* @version 1.0, 06/07/2010
*
* Method : Recursion & Memoization
* Status : Accepted
* Runtime: 0.124
*/

#include <iostream>
#include <map>

using namespace std;

int k,m,l;
map<long long, double> cache;


double f(long long r, long long b, long long p) // round, bet, profit
{
if(cache.find((r << 50) + (b << 32) + p) != cache.end())
return cache[((r << 50) + (b << 32) + p)];

// stan wins...
if(r > k && p > 0)
return 1.0;

// break recursion at m
if(r > m)
return 0.0;

// reset bet if it exceeds limit
if((1 << b) > l)
b = 0;

// recurse into all possibilities
double sum = 0;
sum += 20.0/28.0 * f(r+1, b+1, p - (1 << b)); // stan looses
sum += 4.0 /28.0 * f(r+1, 0 , p + (1 << b)); // stan hits once
sum += 2.0 /28.0 * f(r+1, 0 , p + (1 << b)*2); // stan hits twice
sum += 2.0 /28.0 * f(r+1, 0 , p + (1 << b)*3); // stan hits triple

cache[((r << 50) + (b << 32) + p)] = sum;

return sum;
}

int main()
{
int testCases;
cin >> testCases;
for(int tc = 0; tc < testCases; tc++)
{
cache.clear();
cin >> k >> m >> l;

printf("%.4f\n",f(1,0,0));
}

return 0;
}