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

package main

import (
	"bufio"
	"os"
	"strings"
	"strconv"
	"log"
	"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<iostream>
#include<iomanip>
#include<string>
#include<cstdlib>
#include<cmath>
#include<algorithm>

using namespace std;

int main() {
	while(1) {
		int n, m;
		cin >> n >> m;
		if(n == 0 && m == 0) break;
		double data[n][n];
		for(int i=0; i<n; i++) {
			for(int j=0; j<n; j++) {
				cin >> data[i][j];
			}
		}

		double dp[n][m];
		for(int i=0; i<n; i++)
			dp[i][0] = 1.0;

		for(int i=1; i<m; i++) {
			for(int j=0; j<n; j++) {
				double max = 0;
				for(int k=0; k<n; k++) {
					double value = dp[k][i-1] * data[k][j];
					if(value > max) max = value;
				}
				dp[j][i] = max;
			}
		}

		double ans = 0;
		for(int i=0; i<n; i++) {
			if(ans < dp[i][m-1]) ans = dp[i][m-1];
		}
		cout << fixed << setprecision(2) << ans << endl;
	}
	return 0;
}

C++: #include <iostream>

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)
		serch(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 < n; ++j) {
				cin >> map[i][j];
			}
		for(int i=0; i < n; ++i)
			search(i, 1.0, 1);
		printf("%.2f\n", Max);
	}
	return 0;
}

C++: #include "bits/stdc++.h"

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int cost[200][200];
int tim[200][200];


int main(){
    int n,m;
    while(cin>>n>>m){
        if(n==0&&m==0)break;
        double data[200][200];
        rep(i,n){
            rep(j,n){
                cin>>data[i][j];
            }
        }
        double dp[200][200];
        rep(i,200)rep(j,200)dp[i][j]=-1;
        rep(i,n){
            dp[i][1]=1;
        }
        for(int i=2;i<=m;i++){
            rep(j,n){
                rep(k,n){
                    dp[j][i] = max(dp[j][i],dp[k][i-1]*data[k][j]);
                }
            }
        }
        double ans=-1;
        rep(i,n){
            ans=max(ans,dp[i][m]);
        }
        printf("%.2lf\n",ans);

    }
}

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 <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	int n,m;
	while(cin>>n>>m,n||m){
		VV(double) vv;
		initvv(vv, n, n);
		rep(i,n){
			rep(j,n){
				cin>>vv[i][j];
			}
		}
		vector<double> dist(n,1.0);
		rep(i,m-1){
			vector<double> pre = dist;
			dist = vector<double>(n,0.0);
			rep(j,n){
				rep(k,n){
					maxs(dist[j], pre[k]*vv[k][j]);
				}
			}
		}
		double ans = 0.0;
		rep(i,n){
			maxs(ans, dist[i]);
		}
		printf("%.2lf\n", ans);
	}	
}


signed main() {
    mainmain();
}