Go: // n×nの成長度表に現れる数字を重複を許してm-1個選んで掛け合わせる時の最大値を求める
// ->掛け算型のDP

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		buf := strings.Split(scanner.Text(), " ")
		n, _ := strconv.Atoi(buf[0])
		m, _ := strconv.Atoi(buf[1])
		if n == 0 && m == 0 {
			break
		}
		growth_table := make([][]float64, n)
		for i := range growth_table {
			scanner.Scan()
			buf_ := strings.Split(scanner.Text(), " ")
			tmp := make([]float64, n)
			for j := range tmp {
				tmp[j], _ = strconv.ParseFloat(buf_[j], 64)
			}
			growth_table[i] = tmp
		}
		dp := make([][]float64, m)
		for i := range dp {
			dp[i] = make([]float64, n)
		}
		for i := range dp {
			dp[0][i] = 1
		}
		for k := 1; k < m; k++ {
			// k個使うとき...
			for i := 0; i < n; i++ {
				for j := 0; j < n; j++ {
					// 新たにgrowth_table[i][jを使うかどうか
					dp[k][j] = max(dp[k][j], dp[k-1][i]*growth_table[i][j])
					// check(dp)
				}
			}
		}
		ans := 0.0
		for i := 0; i < n; i++ {
			if dp[m-1][i] > ans {
				ans = dp[m-1][i]
			}
		}
		fmt.Printf("%.2f\n", ans)
	}
}

func max(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

// func check(dp [][]float64) {
// 	log.Println()
// 	for i := range dp {
// 		log.Println(dp[i])
// 	}
// 	log.Println()
// }

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

int n, m;
double dp[101][101];

double solve(int prev, int cnt, const vector<vector<double> >& manure)
{
  if (cnt >= m)
    return 1.0;

  if (dp[prev][cnt] != -1.0)
    return dp[prev][cnt];

  double res = 0.0;
  for (int i = 0; i < n; ++i)
    res = max(res, solve(i, cnt+1, manure) * manure[prev][i]);

  return dp[prev][cnt] = res;
}

int main()
{

  while (cin >> n >> m) {
    if ((n|m) == 0)
      break;

    vector<vector<double> > manure(n+1, vector<double>(n+1, 1.0));
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j)
	cin >> manure[i][j];
    }

    for (int i = 0; i < 101; ++i) {
      for (int j = 0; j < 101; ++j)
	dp[i][j] = -1.0;
    }

    printf("%.2f\n", solve(n, 0, manure));
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <functional>
#include <numeric>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <set>

using namespace std;

#define ALL(co) co.begin(), co.end()
#define tpl(...) make_tuple(__VA_ARGS__)

typedef long long LL;
typedef pair<int, int> P; typedef pair<int, P> IP; typedef pair<P, P> PP;
typedef vector<int> Array; typedef vector<vector<int> > Array2;
typedef vector<LL> LArray; typedef vector<P> PArray; typedef vector<string> SArray;

const int INF = 1 << 29;
const LL LINF = 1LL << 60;

inline int getInt() { int itiv; return (cin >> itiv, itiv); }
template <typename T> void readAll(vector<T>& vec) { for (int i = 0, size = vec.size(); i < size; i++) cin >> vec[i]; }
template <typename T, typename U> void readAll(vector<pair<T, U> >& vec) { for (int i = 0, size = vec.size(); i < size; i++) cin >> vec[i].first >> vec[i].second; }
template < typename T > inline string toString( const T &a ){ ostringstream oss; oss << a; return oss.str(); };
inline bool between(int min, int max, int n) { return min <= n && n <= max; }
inline bool inRange(int begin, int end, int n) { return begin <= n && n < end; }
inline bool inRange(int size, int n) { return 0 <= n && n < size; }

int dx[] = { -1, 0, 1, 0 }, dy[] = { 0, -1, 0, 1 };
int dr[] = { 0, -1, 0, 1 }, dc[] = { -1, 0, 1, 0 };

int m, n;

int main(void)
{
	while(cin >> n >> m && n)
	{
		vector<vector<double> > table(n, vector<double>(n));
		for (int i = 0; i < n; i++)
		{
			readAll(table[i]);
		}
		
		vector<double> next(n);
		vector<double> now(n, 1);

		for (int i = 1; i < m; i++)
		{
			for (int j = 0; j < n; j++)
			{
				next[j] = now[0] * table[j][0];
				for (int k = 0; k < n; k++)
				{
					next[j] = max(next[j], now[k] * table[j][k]);
				}
			}
			now = next;
		}
		printf("%.2f\n", *max_element(ALL(now)));
	}
	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back
#define F first
#define S second

const int MAX=100;

int main(void)
{
  int n,m,i,j,k;
  double g[MAX][MAX+1],dp[MAX][MAX+1],res;//mñÚ,níÞ
  for(;;){
    scanf("%d%d",&n,&m); if(!n)break;
    rep(i,n)rep(j,m)dp[j][i]=j?0.0:1.0;
    rep(i,n)rep(j,n)scanf("%lf",g[i]+j);
    rep(i,m)rep(j,n)rep(k,n){
      dp[i+1][k]=max(dp[i+1][k],dp[i][j]*g[j][k]);
    }
    res=0;
    rep(i,m)res=max(res,dp[i][n-1]);
    printf("%.2f\n",res);
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
using namespace std;
double key[100][100];
double table[100][100];

void Init(int n, int m){
	for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) table[i][j] = 0;
}

double memo(int cur, int count, int limit, int kind){
	if(table[cur][count]) return table[cur][count];
	if(count==limit) return 1.0;
	double Max = 0;
	int prev = 0;
	for(int i = 0; i < kind; i++){
		double tmp = memo(i, count+1, limit, kind);
		if(Max <= tmp){
			if(Max*key[prev][cur] < tmp*key[i][cur]){
				Max = tmp;
				prev = i;
			}
		}
	}
	table[cur][count] = Max*key[prev][cur];
	return table[cur][count];
}

int main(){
	int n, m;
	while(cin >> n >> m && ((n!=0)||(m!=0))){
		Init(n, m);
		for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) cin >> key[i][j];
		for(int i = 0; i < n; i++) table[i][0] = memo(i, 0, m, n);
		double max = 0;
		for(int i = 0; i < n; i++) if(max < table[i][0]) max = table[i][0];
		printf("%0.2f\n", max);
	}

	return 0;
}

C++: #define _USE_MATH_DEFINES
#define INF 10000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int,string> P;

static const double eps = 1e-8;

double dp[101][101];
double table[100][100];

int main(){

	int n,m;
	while(~scanf("%d %d",&n,&m)){
		if(n==m && m==0) break;
		for(int y=0;y<n;y++){
			for(int x=0;x<n;x++){
				scanf("%lf",&table[y][x]);
			}
		}

		fill((double*)dp,(double*)dp+101*101,0.0);
		for(int i=0;i<n;i++) dp[0][i] = 1.0;

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

		double res = -1.0;
		for(int k=0;k<m;k++) for(int i=0;i<n;i++) res = max(res,dp[k][i]);

		printf("%.2lf\n",floor(res+0.005+eps));
	}
}