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 <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
using namespace std;

double dp[31][31 * 10000];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n, m, e;
	while(cin >> n >> m >> e, n | m | e) {
		assert(n <= 30 && n * m <= 30 * 10000);
		for(int i = 0; i <= n; i++) {
			for(int j = 0; j <= n * m; j++) {
				dp[i][j] = 0;
			}
		}

		dp[0][0] = 1.0;
		for(int i = 0; i < n; i++) {
			for(int j = 0; j <= m * i; j++) {
				dp[i + 1][j + 1] += dp[i][j] / m;
				dp[i + 1][j + m + 1] -= dp[i][j] / m;
			}
			double s = 0;
			for(int j = 0; j <= m * (i + 1); j++) {
				s += dp[i + 1][j];
				dp[i + 1][j] = s;
			}
		}

		double ans = 0;
		for(int j = n; j <= m * n; j++) {
			int b = j - e;
			if(b <= 1) ans += dp[n][j];
			else ans += b *  dp[n][j];
		}

		cout << setprecision(15) << ans << endl;
	}
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

double d[100][10000];
int main(){
	int n,m,k;
	while(1){
		cin >> n >> m >> k;
		if(n==0&&m==0&k==0) break;
		REP(i,100) REP(j,10000) d[i][j] = 0;
		d[0][0] = 1.0;
		REP(i,n){
			REP(j,10000){
				if(d[i][j]<0.00001) continue;
				FOR(p,1,m+1){
					d[i+1][j+p] += d[i][j]*(1.0/double(m));
				}
			}
		}
		double res = 0;
		REP(i,10000){
			 // if(d[n][i]!=0) cout << i << "  " << d[n][i] << endl;
			int num = max(i-k,1);
			res += d[n][i]*num;
		}
		cout << shosu(8) << res << endl;
	}
}

C++: #include <stdio.h>
#include <memory.h>
#include <math.h>
#include <vector>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)

//FILE *in = freopen("input.txt", "r", stdin);

int n, m, k;
vector<int> cnt;

void back(int lev, int sum) {
	if (lev == n) {
		cnt[sum]++;
		return;
	}
	rep(i, m) {
		back(lev+1, sum+i+1);
	}
}

void process() {
	long long sum = 0;
	long double q = pow((long double)m, n);
	cnt.clear();
	cnt.assign(m*n+1,0);
	back(0, 0);
	for(int i = m*n; i > 0; i--) {
		int bills = i - k;
		if(bills < 1) bills = 1;
		sum += bills * cnt[i];
	}

	long double res = sum / q;
	printf("%.10Lf\n", res);
}

int main() {
	while(true) {
		scanf("%d%d%d", &n, &m, &k);
		if (!n) break;
		process();
	}
	return 0;
}

C++: 
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
using namespace std;

using LL = long long;

int main(void)
{
	cout.precision(15);
	cout << fixed;
	for (;;)
	{
		int n, m, k;
		cin >> n >> m >> k;
		if (!n)break;
		//dp(i,j):=i??????m??¢???????????§j?????????????????°
		//dp[i][j] = dp[i-1][j-k](k=1~m)
		map<pair<int, int>, LL>dp;
		if (n == 1)
		{
			for (int kk = 1; kk <= m; ++kk)
			{
				dp[{1, kk}] = 1;
			}
		}
		else
		{
			dp[{0, 0}] = 1;
			for (int i = 1; i <= n; ++i)
			{
				for (int j = 0; j <= i * m; ++j)
				{
					for (int kk = 1; kk <= m; ++kk)
						dp[{i, j}] += dp[{i - 1, j - kk}];
				}
			}
		}
		LL ans = 0;
		LL div = 0;
		for (int j = 0; j <= n * m; ++j)
		{
			int score = max(1, j - k);
			ans += dp[{n, j}] * score;
			div += dp[{n, j}];
		}
		cout << (double)ans / div << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int main()
{
    int m, n, k;
    
    // n <= 21
    while (scanf("%d %d %d", &n, &m, &k) && n){
        double dp[2][10001];
        
        for (int i = 0; i <= m * n; i++){
            dp[0][i] = dp[1][i] = 0;
        }
        
        int t = 0;
        dp[0][0] = 1;
        
        for (int i = 1; i <= n; i++){
            for (int j = 0; j <= m * n; j++) dp[1 - t][j] = 0;
            for (int j = 0; j <= m * (n - 1); j++){
                for (int d = j + 1; d <= j + m; d++){
                    dp[1 - t][d] += dp[t][j] / m;
                }
            }
            t = 1 - t;
        }
        
        double r = 0;
        for (int i = 1; i <= m * n; i++) r += max(1, i - k) * dp[t][i];
        
        printf("%.10f\n", r);
    }
    
    return (0);
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <string.h>

#define MAX 10000000

long long dp1[MAX];
long long dp2[MAX];

using namespace std;

int main(void)
{
	int n,m,k;
	int i1,i2,i3;
	double ans;
	double poww;

	while(1){
		cin>>n>>m>>k;
		if(n+m+k==0) break;

		for(i1=0;i1<=n*m;i1++){
			dp1[i1]=0;
			dp2[i1]=0;
		}

		for(i1=1;i1<=m;i1++){
			dp1[i1]=1;
		}

		for(i1=1;i1<n;i1++){
			for(i2=1;i2<=n*m;i2++){
				if(dp1[i2]!=0){
					for(i3=1;i3<=m;i3++) dp2[i2+i3]+=dp1[i2];
				}
			}

			for(i2=1;i2<=n*m;i2++){
				dp1[i2]=dp2[i2];
				dp2[i2]=0;
			}
		}

		/*	for(i3=0;i3<=n*m;i3++){
				cout<<i3<<" "<<dp1[i3]<<endl;
			}*/

		ans=0;
		poww=pow((double)m,n);

		for(i1=1;i1<=n*m;i1++){
			if((i1-k)<=0) {
				ans+=(dp1[i1]/poww);
				//cout<<"1 "<<dp1[i1]<<" "<<poww<<endl;
			}
			else {
				ans+=((dp1[i1]/poww)*(double)(i1-k));
				//cout<<i1-k<<" "<<dp1[i1]<<" "<<poww<<endl;
			}
		}

		printf("%.8lf\n",ans);

	}
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll n, m, k, sum;

void dfs(ll dep, double wa)
{
    for (int i = 1; i <= m; i++)
    {
        if (dep == n)
        {
            if ((wa + i - k) < 1)
                sum += 1;
            else
                sum += (wa + i - k);
        }
        else
            dfs(dep + 1, wa + i);
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    while (true)
    {
        sum = 0;
        cin >> n >> m >> k;
        if (n == 0 && m == 0 && k == 0)
            break;
        dfs(1, 0);
        double bunbo = 1;
        for (int i = 0; i < n; i++)
            bunbo *= m;
        //cout<<sum<<endl<<bunbo<<endl;
        cout << fixed << setprecision(10) << sum / bunbo << endl;
    }
    return 0;
}