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<cmath>
#include<cstdio>
 
using namespace std;
 
long double denominator,ans;
int n,m,k;
 
void solve(int rev,int sum){
  if(rev){
    for(int i = 1; i <= m; i++)
      solve(rev-1,sum+i);
  }else{
    sum = max(1,sum-k);
    ans += (long double)sum/denominator;
  }
}
 
int main(){
 
  while(cin >> n >> m >> k && n+m+k){
    ans = 0;
    denominator = pow((double)m,(double)n);
    solve(n,0);
    printf("%.8Lf\n",ans);
  }
  return 0;
}

C++: #include<iostream>
#include<math.h>
#include<iomanip>

using namespace std;

typedef long long ll;

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

int main(){
    while(1){
        int n, m, K;
        cin >> n >> m >> K;
        if(n==0){
            break;
        }

        ll dp[n+1][m*n+1];
        REP(i, n+1){
            REP(j, m*n+1){
                dp[i][j] = 0;
            }
        }

        dp[0][0] = 1;
        REP(i, n){
            REP(j, m*(i+1)){
                int k;
                if(j>=m){
                    k = m;
                } else {
                    k = j+1;
                }

                ll s = 0;
                REP(l, k){
                    s += dp[i][j-l];
                }
                dp[i+1][j+1] = s;
            }
        }

        ll sum[n*m+1];
        REP(i, n*m){
            sum[i+1] = 0;
        }

        REP(i, n*m){
            if(i+1<=K){
                sum[1] += dp[n][i+1];
            } else {
                sum[i+1-K] += dp[n][i+1];
            }
        }

        /*
        REP(i, n*m){
            cout << sum[i+1] << " ";
        }
        cout << endl;
        */

        ll d = pow(m, n);
        double exp = 0;
        REP(i, n*m){
            exp += double(sum[i+1]) * (i+1) / d;
        }

        cout << fixed << setprecision(8) << exp << endl;
    }
}

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

int pow(int m, int n)
{
  if (n == 1) {
    return m;
  }
  if (n == 0) {
    return 1;
  }
  if (n % 2 == 0) {
    return pow(m, n / 2) * pow(m, n / 2);
  } else {
    return m * pow(m, n - 1);
  }
}

int comb(int n, int m, int k)
{
  if (n == 1) {
    if (1 <= k && k <= m) {return 1;}  
    else {return 0;}
  }
  if (k > m * n || k < n) {return 0;}
  
  int sum = 0;
  for (int i = 1; i <= m; i++) {
    if (i >= k) {break;}
    sum += comb(n - 1, m, k - i);
  }
  return sum;
}

int main()
{
  int n, m, k;
  while (scanf("%d %d %d ", &n, &m, &k) == 3) {
    if (n == 0 && m == 0 && k == 0) {break;}
    double E = 0;
    if (n == 1) {      
      E = (m - k) * (m - k + 1) / 2 + k;
    } else {
      for (int i = n; i <= n * m; i++) {
	//printf("%d %d %d = %d\n", n, m, i, comb(n, m, i));
	if (i<= k) {
	  E += comb(n, m, i);
	} else {
	  E += comb(n, m, i) * (i - k);
	}
      }
    }
  printf("%l.8f\n", E / pow(m, n));
  }
  return 0;
}

C++: #include<iostream>
#include<iomanip>

using namespace std;

int main(void){

  int n,m,k;
  double *v_table,*v_table_tmp;
  //unsigned long long *v_table,*v_table_tmp;

  for(cin>>n,cin>>m,cin>>k;n!=0 or m!=0 or k!=0;cin>>n,cin>>m,cin>>k){

    v_table = new double[n*m+1];
    //v_table = new unsigned long long[n*m+1];
    v_table_tmp = new double[n*m+1];
    //v_table_tmp = new unsigned long long[n*m+1];    
    
    //cout << n << "," << m << "," << k << endl;
    
    for(int i=0;i<n;i++){
      for(int j=0;j<m;j++){
	v_table[i*m+j+1] = 0;
	v_table_tmp[i*m+j+1] = 0;	
      }
    }
    v_table[0] = 1.0;
    
    for(int i=1;i<=n;i++){

      for(int c_i=0;c_i<n;c_i++){
	for(int c_j=0;c_j<m;c_j++){
	  v_table_tmp[c_i*m+c_j+1] = 0;	
	}
      }
      
      for(int j=i;j<=i*m;j++){

	for(int k=j-m;k<j;k++){
	  if(k < 0) continue;
	  else{
	    v_table_tmp[j] += v_table[k]/m;
	    //v_table_tmp[j] += v_table[k];	    
	  }
	}
	
      }

      for(int c_i=0;c_i<n;c_i++){
	for(int c_j=0;c_j<m;c_j++){
	  v_table[c_i*m+c_j+1] = v_table_tmp[c_i*m+c_j+1];
	}
      }
      v_table[0] = 0;

      for(int c_i=0;c_i<n;c_i++){
	for(int c_j=0;c_j<m;c_j++){
	  //cout << "v[" << c_i*m+c_j+1 << "]:" << v_table[c_i*m+c_j+1] << endl;
	}
      }
      //cout << "~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
    }
    

    double exp=0;

    for(int c_i=0;c_i<n;c_i++){
      for(int c_j=0;c_j<m;c_j++){
	//cout << "v[" << c_i*m+c_j+1 << "]:" << v_table[c_i*m+c_j+1] << endl;
	if(c_i*m+c_j+1 <= k){
	  exp += v_table[c_i*m+c_j+1];
	}
	else{
	  exp += (c_i*m+c_j+1-k)*v_table[c_i*m+c_j+1];	    
	}
      }
    }
    //cout << "exp:" << exp << endl;
    cout << fixed << setprecision(8) << exp << endl;        
    delete[] v_table;      
    //cout << "++++++++++++++++++++++++++++++++++++++++++" << endl;    
    
  }
  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
int main() {
	int n, m, k;
	while (cin >> n >> m >> k, n) {
		if (n > 1) {
			double r = 1; double out = 0;
			rep(i, n) {
				r *= m;
			}
			ll cnt = 0; int dp[200] = {};
			dp[0] = 1;
			rep(i, n) {
				for (int j = 199; j >= 0; j--) {
					rep1(k, m) {
						if (j + k < 200) {
							dp[j + k] += dp[j];
						}
					}
					dp[j] = 0;
				}
			}
			rep(i, 200) {
				int x = i - k;
				if (x <= 0)x = 1;
				out += ((ll)dp[i] * (ll)x)/r;
			}
			cout << fixed << setprecision(8) << out << endl;
		}
		else {
			double out = 0;
			rep1(i, m) {
				int x = i - k;
				if (x <= 0)x = 1;
				out += x/(double)m;
			}
			cout << fixed << setprecision(8) << out << endl;
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

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

void rec(int i, int sum) {
	if (i == n) { cnt[max(1, sum - k)]++; }
	else { for (int x=1; x<=m; ++x) rec(i+1, sum + x); }
}

int main() {
	while (cin >> n >> m >> k, n>0) {
		cnt = map< int, int >();
		rec(0, 0);
		
		int T = 1;
		for (int i=0; i<n; ++i) T *= m;
		
		double ans = 0;
		for (auto it : cnt) {
			int a = it.first, b = it.second;
			ans += a * (double)b / T;
		}
		printf("%.9lf\n", ans);
	}
}