Go: package main

import (
	"fmt"
	"math"
)

func main(){
	var n, m, k int
	for {
		fmt.Scan(&n, &m, &k)
		if n == 0 && m == 0 && k == 0{
			break
		}

		dp := make([][]int, n+1)
		for i:= 0; i < n+1; i++{
			dp[i] = make([]int, m*n + 1)
		}

		for i := 1; i <=m ; i++{
			dp[1][i] = 1
		}

		for i:= 1; i < n; i++{
			for j := 0; j <= i * m; j++{
				for k := 1; k <= m; k++{
					dp[i+1][j+k] += dp[i][j]
				}
			}
		}

		count := 0.0
		div := math.Pow(float64(m), float64(n))
		for i := 0; i <= n * m; i++{
			bill := 0.0
			if i <= k{
				bill = 1.0
			} else {
				bill = float64(i - k)
			}
			count += bill * float64(dp[n][i]) / div
		}
		fmt.Printf("%.010f\n", count)
	}
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
using namespace std;

map< pair<int,int> ,double> dp;

int n,m,k;
double dfs(int sum,int n){
	if( dp.count({sum,n}) ) return dp[{sum,n}];
	if( sum < 0 ) return 0.0;
	if( sum == 0 ){	
		return n == 0 ? 1.0 : 0.0;
	}
	if( n <= 0 ) return 0.0;
	double res = 0;
	for(int i = 1 ; i <= m ; i++){
		res += dfs(sum-i,n-1) / m;
	}
	return dp[{sum,n}] = res;
}

int main(){
	while( cin >> n >> m >> k && n){
		dp.clear();
		double sum = 0;
		if( n == 1 ){
			for(int i = 1 ; i <= m ; i++)
				sum += (1./m) * max(1,(i-k));
		}else{
			for(int i = 1 ; i <= n * m ; i++){
				double p = dfs(i,n);
				sum += max(1,i-k) * p;
			}
		}
		printf("%.10lf\n",sum);
	}
}

C++: #include <iostream>
#include <vector>
#include <iomanip>
#include <cmath>
using namespace std;

int n, m, k;
void solve(int i, int val, vector<int>& cnt) {
    if(i == n) {
        if(val <= k) {
            cnt[1]++;
        } else {
            cnt[val-k]++;
        }
        return;
    }
    for(int j=1; j<=m; ++j) {
        solve(i+1, val+j, cnt);
    }
}

int main() {
    while(cin >> n >> m >> k, n) {
        vector<int> cnt(n*m+1, 0);
        solve(0, 0, cnt);
        double ret = 0;
        for(int i=0; i<cnt.size(); ++i) {
            ret += i * cnt[i] / static_cast<double>(pow(m, n));
        }
        cout << fixed << setprecision(8) << ret << endl;
    }
}

C++: #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#define REP(i,a,b) for (int i = (a); i < (b); i++)
#define rep(i,a) REP(i,0,a)

using namespace std;

int n,m,k;

int main(void){
    while (cin >> n >> m >> k && n) {
        int dp[n][n * m + 1];
        memset(dp,0,sizeof(dp));
        rep(i, m) dp[0][i + 1] = 1;
        REP(i, 1, n) rep(j, m * n + 1) REP(k, max(0, j - m), j) dp[i][j] += dp[i - 1][k];

        long long s = 0;
        rep(i, m * n + 1) s += dp[n - 1][i];

        double ans = 0.0;
        rep(i, m * n + 1) ans += 1.0 * dp[n - 1][i] / s * max(1, i - k);
        printf("%.10f\n", ans);
    }
    return 0;
}