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 <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));
	
		for(int i = 0; i < n; i++)
		{
			dp[0][i] = 1.0;
		}

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

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

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

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

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

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,b,n) for(int i=b;i<n;i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int n,m;
const int MAX_N =120;
const int MAX_M =120;
double dp[MAX_N][MAX_M];//dp[i][j]:=直前にjを与え、i回目に肥料を与えたときの最大の成長
double memo[MAX_N][MAX_N];
int main(){
	while(cin>>n>>m,n||m){
		for(int i =0;i <MAX_N;i++){
			for(int j =0;j <MAX_N;j++){
				dp[i][j] =0;
				memo[i][j]=0;
			}
		}
		rep(i,n){
			rep(j,n){
				cin>>memo[i][j];
			}
		}
		if(m==1){
			printf("%.02lf\n",1.00);
			continue;
		}
		rep(i,n)dp[1][i] =1;
		double ans =0;
		for(int i =1;i <m;i++){
			for(int j =0;j <n;j++){//直後
				for(int k =0;k <n;k++){//直前
					dp[i+1][j] =max(dp[i+1][j],dp[i][k]*memo[k][j]);
					if(dp[i+1][j]>ans){
						ans =dp[i+1][j];
					}
				}
			}
		}
		ans +=0.005;
		ans =ans*100;
		ans =(int)ans;
		ans =(double)ans/100;
		printf("%.2f\n",ans);
	}
	return 0;
}

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

using namespace std;

int n, m;
double grow[100][100];
double dp[100][100];//

int main() {
	while (cin >> n >> m, n * m) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cin >> grow[i][j];
			}
		}
		for (int i = 0; i < n; i++)dp[0][i] = 1;
		for (int i = 1; i < m; i++) {
			for (int j = 0; j < n; j++) {
				double M = 0;
				for (int k = 0; k < n; k++) {
					M = max(M, dp[i - 1][k] * grow[k][j]);
				}
				dp[i][j] = M;
			}
		}
		double ans = 0;
		for (int i = 0; i < n; i++) {
			ans = max(ans, dp[m - 1][i]);
		}
		cout << fixed << setprecision(2) << ans << endl;
		for (int i = 0; i < n; i++)for (int j = 0; j < n; j++)grow[i][j] = 0;
		for (int i = 0; i < m; i++)for (int j = 0; j < n; j++)dp[i][j] = 0;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

double t[102][102];	// ツ行ツづ個値ツづ債前ツ嘉アツ与ツつヲツつスツ氾ャツ猟ソ,ツ療アツづ個値ツづ債債。ツ嘉アツ与ツつヲツつスツ氾ャツ猟ソ
double dp[102][102];

int main()
{
	int n, m;

	while (cin >> n >> m && n && m ){
		memset (t, 0.0, sizeof (t ) );
		memset (dp, 0.0, sizeof (dp ) );

		rep (i, n ){
			rep (j, n ){
				cin >> t[i][j];
			} // end rep
		} // end rep
		for (int i = 0; i < n; i++ ){
			dp[i][1] = 1.0;
		} // end for
		for (int i = 0; i < n; i++ ){
			for (int j = 2; j <= m; j++ ){
				for (int k = 0; k < n; k++ ){
					dp[i][j] = max (dp[i][j], dp[k][j-1]*t[k][i] );
				} // end for
			} // end for
		} // end for

		double res = 0.0;
		for (int i = 0; i < n; i++ ){
			res = max (res, dp[i][m] );
		} // end for

		printf ("%.02lf\n", res );
	} // end while

	return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int main(){
	int n,m;
	while(cin>>n>>m,n+m){
		double dp[110][110]={0};
		double in[110][110]={0};
		rep(i,n)rep(j,n)cin>>in[i][j];
		rep(i,110)dp[0][i]=1;
		loop(i,1,m){
			rep(j,n)rep(k,n)dp[i][k]=max(dp[i][k],dp[i-1][j]*in[j][k]);
		}
		double ma=-1;
		rep(i,n)ma=max(ma,dp[n-1][i]);
		printf("%.2f\n",ma);
		
	}
}

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

using namespace std;

int N, M;
double FertilizerData[100][100];
double DpResult[100][100];


void solve() {
	double maxData;

	for (int j = 0; j < N; ++j) {
		DpResult[0][j] = 1.0;
	}

	for (int i = 1; i < M; ++i) {
		for (int j = 0; j < N; ++j) {
			for (int k = 0; k < N; ++k) {
				DpResult[i][j] = max(DpResult[i][j], DpResult[i - 1][k] * FertilizerData[k][j]);
			}
		}
	}

	maxData = -0.1;
	for (int k = 0; k < N; ++k) {
		maxData = max(maxData, DpResult[M - 1][k]);
	}
	cout << fixed << setprecision(2) << maxData << endl;
}

int main() {

	while (cin >> N >> M, N) {
		memset(FertilizerData, 0, sizeof(FertilizerData));
		memset(DpResult, 0, sizeof(DpResult));
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				cin >> FertilizerData[i][j];
			}
		}
		////show:
		//for (int i = 0; i < N; ++i) {
		//	for (int j = 0; j < N; ++j) {
		//		cout << FertilizerData[i][j] << " ";
		//	}
		//	cout << endl;
		//}
		solve();
	}

	return 0;
}