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<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
    while(1){
    int n,m,k;
    cin>>n>>m>>k;
    if(n==0)break;
    vector<int> dp(n*m+1,0);
    dp[0] = 1;
    for(int i=0;i<n;i++){
	vector<int> tmp(n*m+1,0);
	for(int j=0;j<=n*m;j++){
	    for(int k=1;j+k<=n*m&&k<=m;k++){
		tmp[j+k] += dp[j];
	    }
	}
	dp = tmp;
    }
    double res = 0;
    double p = pow(m,n);
    for(int i=0;i<=n*m;i++){
	res += (double)(dp[i]*max(1,i-k) )/p;
    }
    printf("%0.10lf\n",res);
    }
    return 0;
}

C++: #include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000
#define MAXN 1000
#define MAXM 10000

typedef long long ll;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

double dp[MAXN][MAXM]; // dp[n][m]はn回サイコロをふったとき合計値がmになる確率

int n, m, k;

int main(void) {
    while (cin >> n >> m >> k) {
        if (n == 0 && m == 0 && k == 0) break;
        for (int i = 0; i < MAXN; i++) 
            for (int j = 0; j < MAXM; j++) 
                dp[i][j] = 0;

        dp[0][0] = 1;
        int ma = n * m;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= ma; j++) {
                for (int k = 1; k <= m; k++) {
                    if (j - k >= 0) {
                        dp[i][j] += dp[i-1][j-k] / m;
                    }
                }
            }
        }
        //for (int i = 0; i <= ma; i++) cout << dp[n][i] << endl;
        double ans = 0;
        for (int i = 1; i <= ma; i++) {
            if (i <= k) ans += 1.0*dp[n][i];
            else ans += (i-k) * dp[n][i];
        }
        printf("%.10f\n", ans);
    }
    return 0;
}

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

const int INF = 1000000007;
const int MOD = 1000000007;

typedef long long ll;
typedef pair<int, int> pr;

int main(){
    int n, m, k;
    while(true){
        scanf("%d%d%d", &n, &m, &k);
        if((n|m|k) == 0) break;
        vector<double> ep(n * m + 1);
        fill(ep.begin(), ep.end(), 0);
        ep[0] = 1;
        for(int i = 0; i < n; ++i){
            for(int j = m * i; j >= 0; --j){
                for(int l = 1; l <= m; ++l){
                    if(j + l > n * m) break;
                    ep[j + l] += ep[j] / m;
                }
                ep[j] = 0;
            }
        }
        double ans = 0;
        for(int i = 0; i <= n * m; ++i){
            ans += max(i - k, 1) * ep[i];
        }
        printf("%.12f\n", ans);
        ep.clear();
    }
    
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
ll n,m;
vector<ll> numCombi(){
    vector<vector<ll>> ret(n+1,vector<ll>(n*m+2,0));
    ret[0][0]=1;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=n*m;j++){
            if(ret[i-1][j]!=0){
                ret[i][j+1]+=ret[i-1][j];
                ret[i][min(j+m,n*m)+1]-=ret[i-1][j];
            }
        }
        partial_sum(all(ret[i]),ret[i].begin());
        //for(auto j:ret[i])cout<<j<<", ";cout<<endl;
    }
    return ret[n];
}

ll factorial(int n){
    if(n==1)return 1;
    return n*factorial(n-1);
}

int main(){
    ll k;
    while(cin>>n>>m>>k,n){
        double ans=0;
        double total=pow(m,n);
        auto v=numCombi();
        int p=k+1;
        for(int i=n;i<p;i++){
            //cout<<i<<": "<<v[i]<<endl;
            ans+=v[i]/total;
        }
        for(int i=p;i<=n*m;i++){
            //cout<<i<<": "<<v[i]<<" * "<<i-p+1<<endl;
            ans+=v[i]/total*(i-p+1);
        }
        cout<<fixed<<setprecision(15)<<ans<<endl;
    }
}

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

int n, m, k;

double rec(int cnt, int sum){
	if(cnt == n){
		if(sum - k < 1) return 1.0 / pow((double)m, (double)n);
		return (double)(sum - k) / pow((double)m, (double)n);
	}
	double ret = 0.0;
	for(int i = 1; i <= m; i++) ret += rec(cnt + 1, sum + i);
	return ret;
}

int main(){
	for(;;){
		scanf("%d %d %d", &n, &m, &k);
		if(n == 0 && m == 0 && k == 0) break;
		printf("%.10lf\n", rec(0, 0));
	}
	return 0;
}

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

int main()
{
  int N, M, K;
  while (cin >> N >> M >> K && N != 0) {
    vector<vector<int> > dp(N, vector<int>(N*M+1, 0));
    for (int j = 1; j <= M; j++) {
      dp[0][j] = 1;
    }
    for (int i = 1; i < N; i++) {
      for (int j = 1; j <= N*M; j++) {
        for (int k = 1; k <= M && j-k >= 0; k++) {
          dp[i][j] += dp[i-1][j-k];
        }
      }
    }

    int n = 0;
    for (int j = 1; j <= N*M; j++) {
      n += dp[N-1][j] * max(1, j-K);
    }
    printf("%.8f\n", double(n)/pow(double(M), double(N)));
  }
  return 0;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    int n,m,k;
    while(cin >> n >> m >> k,n){
        vector<vector<double>> dp(n+1,vector<double>(n*m+1,0));
        dp[0][0]=1.0;
        for (int i=0;i<n;++i){
            for (int j=0;j<=n*m;++j){
                for (int k=1;k<=m&&j+k<=n*m;++k){
                    dp[i+1][j+k]+=dp[i][j]/m;
                }
            }
        }
        double ans=0;
        for (int i=1;i<=m*n;++i){
            ans+=dp[n][i]*max(i-k,1);
        }
        cout << ans << '\n';
    }
}