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>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600

double solve(int n, int m){
  vector<vector<double>> tbl(n,vector<double>(n));
  rep(i,n) rep(j,n) cin>>tbl[i][j];

  vector<vector<double>> dp(m, vector<double>(n, -INF));
  rep(i,n) dp[0][i] = 1.0;
  repl(i,1,m) rep(j,n) rep(k,n) dp[i][j] = max(dp[i][j], dp[i-1][k] * tbl[k][j]);
  return *max_element(all(dp[m-1]));
}

int main(){
  int n,m;
  while(cin>>n>>m, n|m){
    printf("%.2f\n", solve(n,m));
  }

  return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <cmath>
#include <cfloat>
using namespace std;

const int NMAX = 100;

int main() {
  int n, m;
  double dp[2][NMAX];
  double g[NMAX][NMAX];
  double lg[NMAX][NMAX];

  while (1) {
    cin >> n >> m;
    if (!n && !m) {
      break;
    }

    for (int i=0; i<n; ++i) {
      for (int j=0; j<n; ++j) {
        cin >> g[i][j];
        lg[i][j] = log(g[i][j]);
      }
    }
    for (int i=0; i<n; ++i) {
      dp[0][i] = 0.0;
    }

    for (int i=0; i<m-1; ++i) {
      for (int j=0; j<n; ++j) {
        dp[!(i&1)][j] = -DBL_MAX;
        for (int k=0; k<n; ++k) {
          dp[!(i&1)][j] = max(dp[!(i&1)][j], dp[i&1][k] + lg[k][j]);
        }
      }
    }

    double lans = 0.0;
    for (int i=0; i<n; ++i) {
      lans = max(lans, dp[!(m&1)][i]);
    }
    cout << fixed << setprecision(2) << round(exp(lans) * 100) / 100 << endl;
  }
  return 0;
}

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

double g[100][100];
double dp[100][100];

int main(){
	int n, m;
	while(scanf("%d%d", &n, &m), n){
		for(int i = 0; i < n; ++i){
			for(int j = 0; j < n; ++j){
				scanf("%lf", &g[i][j]);
			}
		}

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

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

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

int main() {
	int i,j,k,m,n;
	double a,b,x,y,d[100][100],an[100],bn[100];
	while(cin >> n >> m) {
		if (n==0 && m==0) break;
		for (i=0;i<n;i++) { an[i]=bn[i]=1; for (j=0;j<n;j++) cin >> d[i][j];}
		for (k=0;k<m-1;k++) {
			for (i=0;i<n;i++) { a=0; b=0; 
			  for (j=0;j<n;j++) {
				  x=an[i]*d[i][j]; y=bn[i]*d[i][j];
			    if (x>a) a=x; if (y>a) a=y;
			    if (y<b) b=y; if (x<b) b=x;
			}
			  an[i]=a; bn[i]=b;
		  }
	  }
	  for (i=0,a=0;i<n;i++) a= a < an[i] ? an[i] : a;
	  printf("%.2f\n",a);
  }  			  
  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));
		vector<vector<double>> dp(m, vector<double>(n));
		for (int i = 0; i < n; i++)
		{
			readAll(table[i]);
		}

		dp[0] = vector<double>(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] * table[k][j]);
				}
			}
		}

		printf("%.2f\n", *(max_element(ALL(dp[m - 1]))));
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
main(){
  int n,m;
  while(cin>>n>>m,n){
    double t[n][n],mm=0,dp[m][n]={};
    r(i,n)r(j,n)cin>>t[i][j];
    r(i,n)dp[0][i]=1;
    for(int i=1;i<m;i++)r(j,n)r(k,n)
      dp[i][j]=max(dp[i][j],dp[i-1][k]*t[k][j]);
    r(i,n)mm=max(mm,dp[m-1][i]);
    printf("%.2f\n",mm);
  }
}

C++: #include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <queue>
#include <string>
#include <complex>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define repa(i,s,e) for(int i=s; i<=e; i++)
#define repd(i,s,e) for(int i=s; i>=e; i--)

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int MAX_N = 101;
const int MAX_M = 101;
int N, M;
double table[MAX_N][MAX_N];
double dp[MAX_M][MAX_N]; 

void solve() {
	rep(i,M) rep(j,N) dp[i][j] = 0.0;

	rep(i,N) dp[0][i] = 1.0;
	repa(i,1,M-1) {
		rep(j,N) {
			double maxval = dp[i-1][j];
			rep(k,N) {
				double s = dp[i-1][k] * table[k][j];
				maxval = max(s, maxval);
			}
			dp[i][j] = maxval;
		}
	}

	double maxval = 0.0;
	rep(i,N) {
		maxval = max(maxval, dp[M-1][i]);
	}
	printf("%.6f\n", maxval);
}

int main() {
	while(scanf("%d%d",&N,&M), N|M) {
		rep(i,N) {
			rep(j,N) {
				scanf("%lf", &table[i][j]);
			}
		}
		solve();
	}
}