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 <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
 
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;

template<class T> inline T sq(const T &x){return x*x;}

double g[101][101];
double dp[101][101];
int main(){
	cout.setf(ios::fixed);
	cout.precision(2);

	int n, m;
	while(cin >> n >> m, n|m){
		memset(dp, 0, sizeof(dp));
		rep(i, n) rep(j, n) cin >> g[i][j];
		rep(i, n) dp[0][i] = 1;
		m--;
		rep(i, m){
			rep(j, n){
				rep(k, n){
					dp[i+1][j] = max(dp[i+1][j], dp[i][k]*g[k][j]);
				}
			}
		}
		cout << *max_element(dp[m], dp[m+1]) << endl;
	}


	return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cfloat>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define EACH( v, c ) for ( auto &v : c )

#define ITER( c ) __typeof( (c).begin() )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

typedef vector<double> VD;
typedef vector< VD > VVD;

int main()
{
	cin.tie( 0 );
	ios::sync_with_stdio( false );

	cout.precision( 2 );
	cout << fixed;

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

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

		VVD table( n, VD( n, 0. ) );

		REP( i, 0, n )
		{
			REP( j, 0, n )
			{
				cin >> table[i][j];
			}
		}

		VVD dp( m, VD( n, 0. ) );
		fill( ALL( dp[0] ), 1. );

		REP( i, 0, m - 1 )
		{
			REP( j, 0, n )
			{
				REP( k, 0, n )
				{
					dp[ i + 1 ][k] = max( dp[ i + 1 ][k], dp[i][j] * table[j][k] );
				}
			}
		}

		cout << *max_element( ALL( dp[ m - 1 ] ) ) << endl;
	}

	return 0;
}

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

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)

int main() {
  
  int N, M;
  while(cin >> N >> M && (N|M)) {
    vector<vector<double> > p(N, vector<double>(N, 0));
    rep(i, N) rep(j, N) cin >> p[i][j];
    vector<vector<double> > dp(M, vector<double>(N, 0));
    rep(i, N) dp[0][i] = 1.0;
    REP(k, 1, M) rep(i, N) rep(j, N)
      dp[k][j] = max(dp[k][j], dp[k-1][i]*p[i][j]);

    double res = 0.;
    rep(i, N) res = max(res, dp[M-1][i]);
    
    printf("%.2f\n", res);
  }
  
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
#define MAX 101

int main(){
  double dp[MAX][MAX],nae[MAX][MAX];
  int n,m;

  while(cin >> n >> m, n+m){
    fill(dp[0],dp[MAX-1],1);

    for(int i = 0 ; i < n ; i++)
      for(int j = 0 ; j < n ; j++)
	cin >> nae[i][j];

    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]*nae[k][j]);

    double ans = 0;
    for(int i = 0 ; i < n ; i++)
      for(int j = 0 ; j < n ; j++)
	ans = max(ans,dp[i][j]);

    ans = (int)(ans+0.005);
    printf("%.2f\n" , ans);
  }

  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cassert>
#include<cmath>
#define EPS 1e-10
using namespace std;
int m,n;
double total;
double dp[110][110];
int Just;
//vector<double> matrix[110];
double matrix[110][110];
/*
double rec(int next,int counter){
  if(dp[next][counter] > 0)return dp[next][counter];
  if(counter  == 0){
    return 1.0;
  }
  double HANMA = 0.0,test=0.0;
 
 
  for(int i=0;i<n;i++){   
    
    //HANMA = max(HANMA,rec(i,counter-1)*matrix[next][i]);
    test = rec(i,counter-1)*matrix[next][i];
    if(test > HANMA)HANMA = test;
  }  
  dp[Just][counter] = HANMA;
  return HANMA;
}
*/

int main(){
  
  double In;
 
  while(cin >> n >> m && n && m){
    //for(int i=0;i<=n;i++)matrix[i].clear();
    
    for(int i=m;i>=0;i--)for(int j=0;j<n;j++)dp[j][i] = -10;
   
 

    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	scanf("%lf",&matrix[i][j]);
      }
    }
  for(int i=0;i<n;i++)dp[i][0] = dp[i][1] = 1;

    double ans = -1; 
    for(int i=2;i<=m;i++){
      for(int j=0;j<n;j++){
	ans = -1;
	for(int k=0;k<n;k++)if(ans < dp[k][i-1]*matrix[j][k])ans = dp[k][i-1]*matrix[j][k];
      
	dp[j][i] = ans;
      }
    }  
 
    double Fans = 0;
    for(int i=0;i<n;i++)if(Fans < dp[i][m])Fans = dp[i][m];
      //cout << endl;

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

  }
  return 0;
}

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

using namespace std;

typedef unsigned long long ull;

#define pb push_back
#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

int main(){
    int n, m;
    while(cin >> n >> m, n+m){
        vector<vector<double> > v;
        rep(i, n){
            vector<double> d; double p;
            rep(j, n){cin >> p; d.pb(p);}
            v.pb(d);
        }

        double dp[110][110];
        memset(dp, 0, sizeof(dp));
        rep(i, n) dp[0][i] = 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]*v[k][j]);
                }
            }
        }
        printf("%.9f\n",max(dp[m-1][0], max(dp[m-1][1], dp[m-1][2])));
    }
}