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<cstdio>
using namespace std;

int main(int argc, char *argv[]){
  int n, m, k;
  while(cin >> n >> m >> k, n){
    double ans = 0;
    long long int dp[n + 1][n*m + 1];//num of dice, sum of the spot
    int w = n*m;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= w; j++) {
        dp[i][j] = 0;
      }
    }
    for (int i = 1; i <= w; i++) {
      if(i <= m)
        dp[1][i] = 1;
      else
        dp[1][i] = 0;
    }
    for (int i = 2; i <= n; i++) {
      for (int j = 1; j <= w; j++) {
        for (int k = 1; k <= m; k++) {
          if(k < j)
            dp[i][j] += dp[i - 1][j - k];
        }
      }
    }

    // for (int i = 1; i <= n; i++) {
    //   for (int j = 1; j <= w; j++) {
    //     std::cout << dp[i][j] << " ";
    //   }
    //   std::cout << std::endl;
    // }

    int deno = 1; 
    for (int i = 0; i < n; i++) {
      deno *= m;
    }
    for (int i = n; i <= w; i++) {
      if(i <= k){
        ans += dp[n][i];
      }else{
        ans += dp[n][i] * (i - k);
      }
    }
    printf("%.8lf\n", ans / deno);
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

#define MAX_M 10000
#define MAX_N 25

int n, m, k;

int power_cache[MAX_M][MAX_N];
int power(int x, int p) {
    if (power_cache[x][p] > 0) return power_cache[x][p];
    return power_cache[x][p] = power(x, p-1) * x;
}

int cache[MAX_N][MAX_M*MAX_N];
int pat(int r, int s) {
    if (s < 0) return 0;
    if (r == 0) 
        return (s == 0 ? 1 : 0);
    if (cache[r][s] >= 0) return cache[r][s];
    int cnt = 0;
    for (int i = 1; i <= m; i++) 
        cnt += pat(r-1, s-i);
    return cache[r][s] = cnt;
}

int main() {
    for (int i = 0; i < MAX_M; i++) power_cache[i][0] = 1;
    while (cin >> n >> m >> k, n || m || k) {
        memset(cache, -1, sizeof(cache));
        double e = 0;
        for (int i = 1; i <= n*m; i++)
            e += (double)pat(n, i) / power(m, n) * max(i-k, 1);
        printf("%.10lf\n", e);
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>

using namespace std;

int main(void){
    int n, m, k;
    while (cin>>n>>m>>k && n) {
        vector<vector<int> > dp(n+1, vector<int>(n*m+1, 0));
        dp[0][0] = 1;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n*m+1; j++) {
                if (dp[i][j] == 0) continue;
                for (int dice = 1; dice < m+1; dice++) {
                    dp[i+1][j+dice] += dp[i][j];
                }
            }
        }
        
        double ans = 0;
        for (int i = 0; i < n*m+1; i++) {
            if (dp[n][i] == 0) continue;
            if (i-k < 1) ans += 1 * dp[n][i];
            else ans += (i-k) * dp[n][i];
        }
        printf("%.12lf\n", ans / pow(m,n));
    }
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int main(void) {
  int64 n, m, k;
  while (cin >> n >> m >> k && n+m+k) {
    vector<int64> dice(n * m+1, 0);
    dice[0] = 1;
    int64 al = 1;
    REP(i, n) {
      al *= m;
      vector<int64> dice2(n*m+1, 0);
      REP(j, n*m-m+1) {
        FOR(k, 1, m+1) {
          dice2[j+k] += dice[j];
        }
      }
      swap(dice, dice2);
    }
    double res = 0;
    REP(i, n*m+1) {
      res += (double)(max(i-k, (int64)1) * dice[i]) / al;
    }
    cout << fixed << setprecision(10) << res << endl;
  }
}

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

using namespace std;

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

double dp[30][20000];
//dp[サイコロの個数][目の合計]

double max(int i, int j)
{
	if (i > j) return (double)i;
	else return (double)j;
}

int main(void)
{
	while(1) {
		int n, m, k;
		cin >> n >> m >> k;
		if (n == 0 && m == 0) break;
		dp[0][0] = 1;
		rep(i, n) {
			erep(j, m * i) {
				orep(l, m) {
					dp[i + 1][j + l] += dp[i][j] / m;
				}
			}
		}

		double ans = 0;
		erep(i, m * n) ans += max(1, i - k) * dp[n][i];
		cout << fixed << setprecision(9) << ans << endl;
}
	return 0;
}

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

using namespace std;

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

    int num[15];
    for(int i=1;i<=n;i++) num[i]=1;
    bool end=false;
    double ans=0;
    double a=pow((double)m, (double)n);
    for(;;){
      int sum=0;
      for(int i=1;i<=n;i++){
	sum+=num[i];
      }
      if(sum<=k){
	ans+=1.0/a;
      }else{
	ans+=1.0/a*(double)(sum-k);
      }
      if(num[n]==m){
	num[n]=0;
	for(int t=n-1;;){
	  if(t<=0){
	    end=true;
	    break;
	  }
	  if(num[t]<m){
	    num[t]++;
	    break;
	  }else{
	    num[t]=1;
	    t--;
	  }
	}
	if(end) break;
      }
      num[n]++;
    }
    printf("%.10f\n", ans);
  }
  return 0;
}