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 <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef complex<double> xy_t;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-11;

double dp[30][20000];

int main() {
    cout << fixed;
    cout << setprecision(9);
    while (1) {
        int n, m, K;
        cin >> n >> m >> K;
        if (n == 0) {
            break;
        }
        for (int i = 0; i < 30; i++) {
            fill(dp[i], dp[i] + 20000, 0);
        }
        dp[0][0] = 1;
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j < 20000; j++) {
                if (dp[i - 1][j] > 0) {
                    for (int k = 1; k <= m; k++) {
                        dp[i][j + k] += dp[i - 1][j] / (m * 1.0);
                    }
                }
            }
        }
        double ans = 0;
        double one = 0;
        for (int i = 0; i <= K + 1; i++) {
            one += dp[n][i];
        }
        ans += one;
        for (int i = K + 2; i <= n * m; i++) {
            ans += (i - K) * dp[n][i];
        }
        cout << ans << endl;
    }
}

C++: #include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;

long long int powint(long long int a, long long int b) {
	assert(b >= 0);
	if (b == 0)return 1;
	if (b == 1)return a;
	long long int ans = 1;
	long long int aa = powint(a, b / 2);
	ans *= aa*aa;
	if (b % 2)ans *= a;
	return ans;
}

int main() {
	while (1) {

		int N, M, K; cin >> N >> M>>K;
		if (!N)break;
		double ans = 0;
		for (int i = 0; i < powint(M, N); ++i) {
			vector<int>pips;
			int num = i;
			for (int i = 0; i < N; ++i) {
				pips.push_back(num%M+1);
				num /= M;
			}
			double bill = max(accumulate(pips.begin(), pips.end(), 0) - K, 1);
			ans += bill / (powint(M, N));
		}
		cout << setprecision(22)<<fixed<<ans << endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<cmath>
using namespace std;

typedef long double D;

int n,m,k,N;

D rec(int d,int sum){
  if(d==n){
    sum -= k;
    if(sum<1)sum = 1;
    return (D)sum/N;
  }

  D res = 0;
  for(int i=1;i<=m;i++)res += rec(d+1,sum+i);
  return res;
}

int main(){
  while(scanf("%d%d%d",&n,&m,&k),n+m+k){
    N = pow(m,n);
    printf("%.9Lf\n",rec(0,0));
  }
}

C++: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;

#define BIG_NUM 2000000000

using namespace std;

void func(int N,int M,int K){
	int table[N*M+1],pre[N*M+1],limit = N*M;
	for(int i = 1; i <=limit;i++){
		pre[i] = 0;
	}

	for(int a = 1; a <= M; a++)pre[a] = 1;

	if(N == 1)for(int i = 1; i <= limit; i++){
		table[i] = pre[i];
	}else{
		for(int i = 2; i <= N; i++){
			for(int a =1; a <= limit; a++)table[a] = 0;
			for(int a = limit; a >= 1; a--){
				if(pre[a] > 0){
					for(int b = 1; b <= M; b++)table[a+b] += pre[a];
				}
			}
			for(int a =1; a <= limit; a++)pre[a] = table[a];
		}
	}

	int cut_back = 0;

	for(int i = 1; i <= K+1;i++){
		cut_back += table[i];
	}

	double bunbo = (double)pow(M,N);
	double ans = (double)cut_back/bunbo;

	for(int i = K+2; i <= limit; i++){
		ans += (double)(i-K)*((double)table[i]/bunbo);
	}

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

}

int main(){

	int N,M,K;

	while(true){
		scanf("%d %d %d",&N,&M,&K);
		if(N == 0 && M == 0 && K == 0)break;

		func(N,M,K);
	}

	return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>
#include <array>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)


typedef long long int ll;
typedef double D;      // ??§?¨?????????????double???long double?????????
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
typedef vector<P> VP;


const int INF = (1<<30) - 1;
const D EPS = 1e-9;

#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)

int N, M, K;

int dfs(int cur, int s){
    if(cur == 0){
        return s-K > 0 ? s-K: 1;
    }
    
    int ans = 0;
    for(int i=1; i<=M; i++){
        ans += dfs(cur-1, s+i);
    }
    return ans;
}

void solve(){
    double d = dfs(N, 0);
    for(int i=0; i<N; i++)
        d /= M;
    printf("%.7lf\n", d);
}

//g++ -std=c++0x -msse4.2 -O3
//#include <bits/stdc++.h>
int main(){
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    //cout.precision(16);
    
    while(cin>>N>>M>>K, N|M|K)
        solve();
    
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int n,m,k;
double p;
void dfs(int d,int x){
  if(d==0)
    if(x-k<=0)p+=1;
    else p+=x-k;
  else
    for(int i=1;i<=m;i++)
      dfs(d-1,x+i);
}
int main(){
  while(cin>>n>>m>>k,n){
    p=0;dfs(n,0);
    printf("%.8f\n",p/(double)(pow(m,n)));
  }
}

C++: #include <cstdio>
#include <iostream>
using namespace std;
int main(){
  int n, m, k;
  while(cin >> n >> m >> k, n){
    long long int prob[n*m+1];
    fill(prob,prob+n*m+1,0LL);
    fill(prob+1,prob+m+1,1LL);
    long long int t = m;
    for(int i = 1; i < n; ++i){
      t *= m;
      int acum[m*(i+1)+1];
      fill(acum,acum+m*(i+1)+1,0);
      for(int j = 0; j <= m*(i+1); ++j){
	acum[j+1] = acum[j]+prob[j];
      }
      for(int j = 0; j < i; ++j) prob[j] = 0;
      for(int j = i; j <= m*(i+1); ++j){
	prob[j] = acum[j] - acum[max(0,j-m)];
      }
    }
    double ans = 0.0;
    for(int i = n; i <= n*m; ++i){
      ans += (double)max(1,i-k)*prob[i]/t;
    }
    printf("%.12f\n",ans);
  }
  return 0;
}