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 <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    while(true){
	int m,n;
	cin >> n >> m;
	vector< vector<double> > d(n,vector<double>(n,0.0) );
	if(n == 0 && m == 0) break;
	REP(i,n)REP(j,n) cin >> d[i][j];
	double ans = 0.0;
	vector<double> a(n);
	double dp[2][101];
	REP(i,2)REP(j,101) dp[i][j] = 0;
	REP(i,101) dp[0][i] = 1;
	REP(i,m-1){
	    REP(j,101) dp[1][i] = 0;

	    REP(j,n){
		dp[1][j] = dp[0][0] * d[j][0];
		REP(k,n){
		    dp[1][j] = max(dp[1][j],dp[0][k] * d[j][k]);
		}
	    }
	    swap(dp[0],dp[1]);
	}
	REP(i,n) ans = max(dp[0][i],ans);
	int t = ans * 1000;
	t = t % 10;
//	if(t >= 5) ans += 0.01;
	printf("%.2f\n",ans);
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <climits>
#include <stdio.h>

using namespace std;

typedef vector < double > VI;
typedef vector < VI > VVI;

int main () {
	int n, m;

	while ( true ) {
		cin >> n >> m;

		if ( !n && !m ) {
			break;
		}

		VVI g(n + 1, VI(n + 1, 0));
		VVI dp(m + 1, VI(n + 1, 0));

		for(int i = 1; i <= n; i++) {
			for(int j = 1; j <= n; j++) {
				cin >> g[i][j];
			}
		}

		for(int i = 0; i <= n; i++) {
			dp[0][i] = 1;
		}

		for(int i = 0; i < m; i++) {
			for(int j = 0; j <= n; j++) {
				if(dp[i][j] > dp[i + 1][j]) {
					for(int k = 1; k <= n; k++) {
						for(int l = 1; l <= n; l++) {
							if(dp[i][j] * g[k][l] > dp[i + 1][j]) {
								dp[i + 1][j] = dp[i][j] * g[k][l];
							}
						}
					}
				}
			}
		}

		double ans = 0;

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

		//for(int i = 0; i <= n; i++) {
		//	for(int j = 0; j <= m; j++){
		//		cout << dp[i][j] << " ";
		//	}
		//	cout << endl;
		//}

		printf("%.2f\n", ans);
	}
}

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

int n, m;
//memo[i][j]: 直前にjを入れてi回目のときの最大倍率
//a[i][j]: 直前i
double a[101][101], memo[101][101];

double rec(int i, int j){
	if(memo[i][j] >= 0){
		return memo[i][j];
	}

	if(i == m){
		return 1;
	}

	double res = 0;
	for(int u=1;u<=n;u++){
		res = std::max(res, a[j][u] * rec(i+1, u));
	}

	return memo[i][j] = res;
}

int main(){
	while(std::cin >> n >> m, n){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				std::cin >> a[i][j];
			}
		}

		for(int i=1;i<101;i++){
			a[0][i] = 1;
		}

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

		double res = rec(0, 0);

		res *= 100;
		res = static_cast<int>(res + 0.5);
		res /= 100;
		
		printf("%.2f\n", res);
	}
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int n, m;
double table[128][128], memo[128][128];
double maxGrow[128];

double rec(int p, int prv)
{
	if(p == 0) return maxGrow[prv];
	if(memo[p][prv] != -1) return memo[p][prv];
	
	double res = -1;
	for(int i = 0; i < n; i++) chmax(res, table[prv][i] * rec(p - 1, i));
	
	
	return memo[p][prv] = res;
}

int main()
{
	int i, j;
	while(cin >> n >> m && n)
	{
		rep(i, n) rep(j, n) cin >> table[i][j];
		
		rep(i, 128) maxGrow[i] = *max_element(table[i], table[i] + 128);
		rep(i, 128) rep(j, 128) memo[i][j] = -1;
		rep(i, 128) table[127][i] = 1.0;
		
		printf("%.2lf\n", rec(m - 1, 127));
	}	
}

C++: #include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;

int main()
{
	double memo1[100] = {};
	double memo2[100] = {};
	double data[100][100];
	int n, m;

	while (true)
	{
		cin >> n >> m;
		if (n + m == 0) return 0;

		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < n; j++)
			{
				cin >> data[i][j];
			}
			memo1[i] = 1.0;
		}

		for (int i = 0; i < m - 1; i++)
		{
			for (int j = 0; j < n; j++)
			{
				for (int k = 0; k < n; k++)
				{
					memo2[k] = max(memo2[k], memo1[j] * data[j][k]);
				}
				memo1[j] = 0;
			}
			swap(memo1, memo2);
		}

		double Max = 0;
		for (int i = 0; i < n; i++)
		{
			Max = max(Max, memo1[i]);
		}
		Max *= 100;
		Max += 0.5;
		Max = (int)Max;
		Max /= 100;
		printf("%.2f\n", Max);
	}
	return 0;
}

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;
const int INF = 1 << 30;

int main()
{
	double T[128][128], dp[128][128];
	int n, m;

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

		for(int i = 0; i < n; i++)
		{
			for(int j = 0; j < n; j++)
			{
				cin >> T[i][j];
			}
		}
		
		memset(dp, 0, sizeof(dp));
		fill(dp[0], dp[0]+m, 1.0);

		for(int i = 1; i < n; i++)
		{
			for(int j = 0; j < m; j++)
			{
				for(int k = 0; k < m; k++)
				{

					//dp[i][k] : i回目で肥料jを使った時の最大の苗木の大きさ
					dp[i][k] = max(dp[i][k], dp[i-1][j]*T[k][j]);
				}
			}
		}

		double res = 0; 
		for(int i = 0; i < m; i++)
		{
			res = max(res, dp[n-1][i]);
		}
	
		res *= 100;
		res = int(res+0.5);
		res /= 100;

		printf("%.2f\n",res);
	}
}