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

package main

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

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 <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 rec(int p, int prv)
{
	if(p == 0) return 1.0;
	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) rep(j, 128) memo[i][j] = -1;
		
		double ans = -1;
		
		rep(i, n) chmax(ans, rec(m - 1, i));
		
		printf("%.2lf\n", ans);
	}	
}

C++: // 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

const pair<int, int> NIL(-1, -1);

double mat[110][110], tmp[110][110];
 
signed main() {
    int N, M;
    while(cin >> N >> M, N) {
        for(int i=0; i<N; i++) {
            for(int j=0; j<N; j++) {
                cin >> mat[i][j];
            }
        }

        cout << fixed << setprecision(2);
        if(M == 1) cout << 1.0 << endl;
        else {
            for(int k=0; k<M-2; k++) {
                fill(tmp[0], tmp[N], 0);
                for(int j=0; j<N; j++) {
                    double ma = -1;
                    for(int i=0; i<N; i++) {
                        chmax(ma, mat[i][j]);
                    }
                    for(int i=0; i<N; i++) {
                        chmax(tmp[j][i], mat[j][i] * ma);
                    }
                }
                swap(mat, tmp);
            }

            double ans = -1;
            for(int i=0; i<N; i++) {
                for(int j=0; j<N; j++) {
                    chmax(ans, mat[i][j]);
                }
            }
            cout << ans << endl;
        }
    }
    return 0;
}

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

int main()
{
  for(;;){
    int n,m;
    cin >> n >> m;
    if(n==0){return 0;}
    double map[n][n];
 
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	cin >> map[i][j];
      }
    }
  
    double dp[m][n];

   
  
    for(int i=0;i<m;i++){for(int j=0;j<n;j++){dp[i][j]=-1.0;}}
    for(int i=0;i<n;i++){dp[0][i]=1.0;}
  
    for(int i=0;i<m;i++){
      for(int j=0;j<n;j++){
	for(int k=0;k<n;k++){
	  dp[i+1][k]=max(dp[i+1][k],dp[i][j]*map[j][k]);
	}
      }
    }
  
    //cout << endl;
    for(int i=0;i<m;i++){
      for(int j=0;j<n;j++){
	//cout << dp[i][j] << " ";
      }
      //cout << endl;
    }

    double max1=-1.0;
    for(int i=0;i<n;i++){
      max1=max(max1,dp[m-1][i]);
    }
    //printf("%f",max1);
    printf("%.2f\n",max1);
  }
}

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

using namespace std;

int main()
{
	for(int n,m;cin>>n>>m,n|m;){
		vector<vector<double> > g(n,vector<double>(n));
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
				cin>>g[i][j];
		
		vector<vector<double> > dp(m,vector<double>(n,0));
		dp[0].assign(n,1);
		for(int i=1;i<m;i++){
			for(int j=0;j<n;j++)
				for(int k=0;k<n;k++)
					dp[i][j]=max(dp[i][j],dp[i-1][k]*g[k][j]);
		}
		
		cout<<fixed<<setprecision(2)<<*max_element(dp[m-1].begin(),dp[m-1].end())<<endl;
	}
	return 0;
}

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

using namespace std;

int n, m;
double map[100][100], Max;

void search( int prev, double point, int count )
{
	if(count == m) {
		if(Max < point) {
			Max = point;
		}
		return;
	}
	for(int i=0; i < n; ++i)
		search(i, point*map[prev][i], count + 1);
}

int main( void )
{
	while(cin >> n >> m, n | m) {
		Max = 0;
		for(int i=0; i < n; ++i)
			for(int j=0; j < m; ++j)
				cin >> map[i][j];
		for(int i=0; i < n; ++i)
			search(i, 1.0, 1);
		int tmp = Max * 1000;
		Max = tmp / 1000.0;
		printf("%.2f\n", Max);
	}
	return 0;
}

C++: #include <iostream>
#include<iomanip>
#include<algorithm>
#define shosu(x) fixed<<setprecision(x)
using namespace std;

int n,m;
double ef[105][105];

double func(){
	double tmp=0,ans=0,dp[105][105];
	for(int i=0;i<m;i++){
		dp[0][i]=1;
	}
	for(int i=1;i<n;i++){
		for(int j=0;j<m;j++){
			for(int k=0;k<m;k++){
				tmp=max(tmp,dp[i-1][k]*ef[k][j]);
			}
			dp[i][j]=tmp;
		}
	}
	for(int i=0;i<m;i++){
		ans=max(ans,dp[n-1][i]);
	}
	return ans;
}

int main(){
	cout<<shosu(2);
	while(1){
		cin>>n>>m;
		if(n==0&&m==0) break;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cin>>ef[i][j];
			}
		}
		cout<<func()<<endl;
	}
}