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 <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 = 1; 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.9f\n", E / pow(m, n));
  }
  return 0;
}

C++: #include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <cstdio>
#include <climits>
#include <cmath>
#include <array>
#include <functional>
#include <sstream>
#include <list>
#include <iomanip>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const double eps=1e-9;
const int inf=1e9;
typedef pair<int,int> P;
struct Point
{
  double x,y;
  Point(){x=0;y=0;}
  Point(double d_x,double d_y){x=d_x,y=d_y;}
  double operator*(Point obj){return obj.x*x+obj.y*y;}
  double operator%(Point obj){return obj.y*x-obj.x*y;}
  Point operator*(double b){Point tmp;tmp.x=x*b;tmp.y=y*b;return tmp;}
  Point operator/(double b){Point tmp;tmp.x=x/b;tmp.y=y/b;return tmp;}
  Point operator+(Point obj){Point tmp;tmp.x=x+obj.x;tmp.y=y+obj.y;return tmp;}
  Point operator-(){Point tmp;tmp.x=-x;tmp.y=-y;return tmp;}
  Point operator-(Point obj){Point tmp;tmp.x=x-obj.x;tmp.y=y-obj.y;return tmp;}
  Point operator-=(Point obj){x-=obj.x;y-=obj.y;return *this;}
  Point operator+=(Point obj){x+=obj.x;y+=obj.y;return *this;}
  Point operator/=(double b){x=x/b;y=y/b;return *this;}
  Point operator*=(double b){x=x*b;y=y*b;return *this;}
  double size(){return hypot(x,y);}
  Point unit(){return Point(x/size(),y/size());}
  Point normal(){return Point(y,-x);}
  double atan(){return atan2(y,x);}
};

bool operator<(Point a,Point b){return a.x!=b.x?a.x<b.x:a.y<b.y;}
bool operator>(Point a,Point b){return b<a;}
bool operator<=(Point a,Point b){return !(b<a);}
bool operator>=(Point a,Point b){return !(a<b);}
bool operator==(Point a,Point b){return (a-b).size()<eps;}
bool operator!=(Point a,Point b){return !(a==b);}

bool equal(double a,double b){return abs(a-b)<eps;}
double cross(Point a,Point b){return a%b;}
double dot(Point a,Point b){return a*b;}

int ccw(Point a,Point b,Point c)
{
  b=b-a;
  c=c-a;
  if(b%c>0) return +1;
  else if(b%c<0)return -1;
  else if(b*c<0) return +2;
  else if(b.size()<c.size()) return -2;
  else return 0;
}

int n,m,k;
vector<int> h1(15);
vector<int> h2(15);

string cmp(string a,string b)
{
  if(a.size()>b.size()) return a;
  if(b.size()>a.size()) return b;
  return max(a,b);
}

int main(int argc,char const* argv[])
{
  while(1)
    {
      cin >> n >> m >> k;
      if(!n) break;
      double dp[2][100005];
      memset(dp,0.0,sizeof(dp));
      dp[0][0]=1.0;
      for(int i=1;i<=n;i++)
	{
	  for(int j=0;j<m*n+1;j++) dp[i%2][j]=0;
	  for(int prev=0;prev<=n*m;prev++)
	    {
	      if(dp[(i+1)%2][prev]==0) continue;
	      for(int k=1;k<=m;k++)
		{
		  int nxt=prev+k;
		  dp[i%2][nxt]+=dp[(i+1)%2][prev]*(double)(1.0/m+0.0);
		}
	    }
	}
      cout << fixed << setprecision(9);
      double ans=0.0;

      for(int j=1;j<=n*m;j++)
	{
	  if(j<=k)
	    {
	      dp[n%2][k+1]+=dp[n%2][j];
	    }
	  else
	    {
	      ans+=dp[n%2][j]*(double)(j-k);
	    }
	}
	
      cout << ans << endl;
    }
  return 0;
}

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

int main()
{
	while (true) {
		int n, m, k;

		cin >> n >> m >> k;

		if (n == 0 && m == 0 && k == 0) {
			break;
		}

		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; j++) {
				if (dp[i][j] == 0) {
					continue;
				}

				for (int l = 1; l <= m; l++) {
					if (j + l > n*m) {
						continue;
					}

					dp[i + 1][j + l] += dp[i][j];
				}
			}
		}

		int sum = 0;

		for (int i = 0; i <= n*m; i++) {
			sum += max(i - k, 1)*dp[n][i];
		}

		cout << fixed << (double)sum / pow(m, n) << endl;
	}

	return 0;
}

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

int n, m, k;
int a[10000];

void solve(int level, int sum)
{
  if(level == 0)
    a[(sum-k > 0)?sum-k:1]++;
  else
    for(int i = 1; i <= m; i++) solve(level-1,sum+i);
}

int main()
{
  while(1){
    cin >> n >> m >> k;
    if(n == 0 && m == 0 && k == 0) break;
    fill(a,a+n*m-k+1,0);
    solve(n,0);
    double e = 0;
    for(int i = 1; i <= n*m-k; i++) e += a[i]*i;
    e /= pow(m,n);
    printf("%.8lf\n", e);
  }
}

C++: #include <bits/stdc++.h>
 
using namespace std;
 
int N,M,K;
map<int,int> mp;
 
void make(int n,int sum){
    if(N == n){
	if(sum-K <= 0){
	    mp[1]++;
	}else{
	    mp[sum-K]++;
	}
	return;
    }
    for(int i = 0 ; i < M ; i++){
	make(n+1,sum+i+1);
    }
}
 
int main(){
    while(cin >> N >> M >> K, N){
	mp.clear();
	make(0,0);
	double ans = 0;
	map<int,int>::iterator it;
	for(it = mp.begin() ; it != mp.end() ; ++it){
	    ans += ((double)it->second/pow((double)M,N))*it->first;
	}
	printf("%.8f\n",ans);
    }
    return 0;
}

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

using namespace std;

int main(){
	int n, m ,k;
	while(cin >> n >> m >> k, n){
		vector<double> cur(n*m+1, 0.0);
		cur[0] = 1.0;
		for(int i=0;i<n;i++){
			vector<double> next(n*m+1, 0.0);
			for(int j=0;j+m<=n*m;j++)
				for(int l=1;l<=m;l++)
					next[j+l] += cur[j]/m;
			cur = next;
		}
		double ans = 0.0;
		for(int i=1;i<=n*m;i++)
			ans += cur[i]*max(1,i-k);
		printf("%.8lf\n", ans);
	}
}