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 <iostream>
#include <cstdio>

const double inf = 1000;

int n, m;
double g[101][101];
double dp[101][101]; //i???????????????j,??????k???????????????????????§???

int main(){
	while(true){
		for(int i = 0; i < 101; ++i){
			for(int j = 0; j < 101; ++j){
				dp[i][j] = -1;
			}
		}
		
		std::cin >> n >> m;
		if(n == 0 && m == 0)break;
		
		for(int i = 0; i < n; ++i){
			for(int j = 0; j < n; ++j){
				std::cin >> g[i][j];
			}
		}
		
		for(int i = 0; i < n; ++i)dp[0][i] = 1.0;
		
		for(int i = 0; i < m - 1; ++i){
			for(int j = 0; j < n; ++j){
				for(int k = 0; k < n; ++k){
					dp[i + 1][k] = std::max(dp[i + 1][k], dp[i][j] * g[j][k]);
				}
			}
		}
		
		double ans = 0;
		for(int i = 0; i < n; ++i){
			if(dp[m - 1][i] > ans)ans = dp[m - 1][i];
		}
		
		printf("%.2f\n", ans);
	}
	
	return 0;
}

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

int main(){
  int n,m;
  double In;
 
  while(cin >> n >> m && n && m){
    vector<double> matrix[n+2];
  
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	cin >> In;
	matrix[i].push_back(In);
      }
    }
    double dp[n+2][m+2];//選んだもの、回数
    for(int i=0;i<n;i++){
      dp[i][0] = dp[i][1] = 1.0; 
      for(int j=2;j<=m;j++){
	dp[i][j] = -1.0;
      }
    }

    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[i][j-1]*matrix[i][k]);
	}
      }
    }
    double ans = -1;
    for(int I=0;I<n;I++)ans = max(ans,dp[I][m]);
    printf("%.2f\n",ans);

  }
  return 0;
}

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

using namespace std;

int n, m;
double in[100][100], dp[101][101];

int main( void )
{
	while(cin >> n >> m, n | m) {

		for(int i=0; i < n; ++i)
			for(int j=0; j < n; ++j) {
				cin >> in[i][j];
				dp[i+1][j] = 0;
			}
		fill(dp[0], dp[0]+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], in[j][k] * dp[i-1][k]);
				}
			}
		}
		double Max = 0;
		for(int i=0; i < n; ++i) {
			Max = max(Max, dp[m-1][i]);
		}
		printf("%.2f\n", Max);
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
#define N 110
#define M 110
double dp[M][N];
double g[M][M];
int n,m;
int main(){
  while(cin>>n>>m&&n+m){
    lol(i,n)lol(j,n)cin>>g[i][j];
    lol(i,n)dp[0][i]=1.0;
    lol(i,m)lol(j,n)dp[i+1][j]=0.0;
    lol(i,m){
      lol(j,n){
	lol(k,n){
	  dp[i+1][k]=max(dp[i+1][k],dp[i][j]*g[j][k]);
	}
      }
    }
    double ans=0;
    lol(i,n)ans=max(ans,dp[m-1][i]);
    int a=ans*1000;
    a=a/10+(a%10>=5?1:0);
    ans=(double)a/100;
    cout<<ans<<endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    while(true){
	int m,n;
	cin >> n >> m;
	vector< vector<double> > d(n,vector<double>(n,0.0) );
	if(n == 0 && m == 0) break;
	REP(i,n)REP(j,n) cin >> d[i][j];
	double ans = 0.0;
	vector<double> a(n);
	double dp[2][101];
	memset(dp,1,sizeof(dp));
	REP(i,101) dp[0][i] = 1;
	REP(i,m-1){
	    REP(j,101) dp[1][i] = 0;
	    REP(j,n){
		REP(k,n){
		    dp[1][j] = max(dp[1][j],dp[0][j] * d[k][j]);
		}
	    }
	    swap(dp[0],dp[1]);
	}
	REP(i,n) ans = max(dp[0][i],ans);
	int t = ans * 1000;
	t = t % 10;
	if(t >= 5) ans = (1000 * ans - t)/1000;
	else (1000 * ans - t + 1)/1000;
	printf("%.2f\n",ans);
    }
    return 0;
}

C++: #include <stdio.h>

double dp[100][100];

#define REP(i, n) for (int i = 0; i < (n); i++)
#define MAX(x, y) ((x) > (y) ? (x) : (y))

int main(void)
{
	double grow[100][100]; //[ツ前ツづ個氾ャツ猟ソ][ツ債。ツづ個氾ャツ猟ソ]
	int n, m;
	
	while (1){
		REP(i, 100) dp[0][i] = 1.0;
		
		scanf("%d%d", &n, &m);
		
		if (n == 0 || m == 0){
			break;
		}
		
		REP(i, n) REP(j, n) scanf("%lf", &grow[i][j]);
		
		for (int i = 1; i < m; i++){
			for (int j = 0; j < n; j++){
				dp[i][j] = dp[i - 1][0] * grow[0][j];
				for (int k = 1; k < n; k++){
					dp[i][j] = MAX(dp[i][j], dp[i - 1][k] * grow[k][j]);
				}
			}
		}
		
		double ans = 0;
		REP(i, n){
			ans = MAX(ans, dp[m - 1][i]);
		}
		
		printf("%.2lf\n", ans);
	}
	return (0);
}

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(int 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];

// m=3
// p=0,prv=2
// p=1,prv=0
// p=2,prv=1
double rec(int p, int prv)
{
	if(p == m - 2) return *max_element(table[prv], table[prv] + 128);
	if(memo[p][prv] != -1) return memo[p][prv];
	
	int sld;
	double res = -1;
	rep(i, n)
	{
		double sub = rec(p + 1, i);
		
		if(res < sub)
		{
			res = sub;
			sld = i;
		}
	}
	
	return memo[p][prv] = table[prv][sld] * res;
}

int main()
{
	while(cin >> n >> m && n)
	{
		rep(i, n) rep(j, n) cin >> table[i][j];
		
		double ans = 0;
		
		rep(i, n)
		{		
			rep(j, 128) rep(k, 128) memo[j][k] = -1;

			chmax(ans, rec(0, i));
		}
		
		printf("%.2f\n", ans);
	}	
}