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<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<utility>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<set>
 
using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+9
#define EPS 1e-9
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = j; i < (k); i++)
typedef long long ll;
double fert[128][128];
double dp[128][128];
int main(){
    int n,m;
    while(scanf("%d%d",&n,&m),(n|m)){
        memset(dp,0,sizeof(dp));
        rep(i,n)rep(j,n)scanf("%lf",&fert[i][j]);
        rep(i,m){
            rep(j,n){
                bool flg = false;
                if(i == 0)dp[i][j] = 1.00;
                else{
                    rep(k,n){
                        dp[i][j] = (!flg) ? dp[i-1][k] * fert[k][j] : max(dp[i][j],dp[i-1][k] * fert[k][j]);
                        flg = true;                    
                    }
                }
            }
        }
        double res = -1.0;
        rep(i,n){
            res = max(res,dp[m-1][i]);
        }  
        printf("%lf\n",res);
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
using namespace std;
double mp[101][101];
double ans;
int n,m;
int sta[101];
int flg;
int cnt;

void saiki(double sum,int mae,int kai) {
  cnt++;
  if(kai == m && sum > ans) ans = sum;

  if(kai < m) {
    for(int i=0;i<n;i++) {
      saiki(sum*mp[mae][i],i,kai+1);
    }
  }
}


int main(){

  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 >> mp[i][j];

    ans = 0;
    for(int i=0;i<n;i++) saiki(1,i,1);

    printf("%.2f\n",ans);
    // cout << cnt <<endl;
  }

  return 0;
}

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

double dp[101][101][101];//dp[i][j][k]=i?????????????????\??????j?????\?????\??????k?????¨??????????????????????????§???
double grow[101][101];//i=??´??????j=??????
		

int main(){
	while(1){
		int m,n;
		std::cin>>m>>n;
		if(m*n==0)break;
		for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)grow[i][j]=0;
		for(int i=1;i<=m;i++)for(int j=1;j<=m;j++)for(int k=1;k<=m;k++)dp[i][j][k]=0;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				std::cin>>grow[i][j];
			}
		}
		for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)dp[1][i][j]=1.0;
		for(int i=2;i<=m;i++){
			for(int j=1;j<=n;j++){
				for(int k=1;k<=n;k++){
					double a=0;
					for(int l=1;l<=n;l++){
						a=std::max(a,dp[i-1][l][k]);
					}
					dp[i][j][k]=a*grow[j][k];
				}
			}
		}
		double ans=0;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++)ans=std::max(ans,dp[m][i][j]);
		}
		std::cout<<std::setprecision(3)<<ans<<std::endl;
	}
	return 0;
}

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

int n, m;
//memo[i][j]: 直前にjを入れてi回目のときの最大倍率
double a[100][100], memo[100][100];

double rec(int i, int j){
	if(memo[i][j] >= 0){
		return memo[i][j];
	}

	if(i == m){
		return 1;
	}

	double res = 0;
	for(int u=0;u<n;u++){
		res = std::max(res, a[u][j] * rec(i+1, u));
	}

	return memo[i][j] = res;
}

int main(){
	while(std::cin >> n >> m, n){
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				std::cin >> a[i][j];
			}
		}

		double res = 0;
		for(int i=0;i<n;i++){
			for(int j=0;j<100;j++){
				for(int k=0;k<100;k++){
					memo[j][k] = -1;
				}
			}
			res = std::max(res, rec(1, i));
		}

		res *= 100;
		res = static_cast<int>(res + 0.5);
		res /= 100;
		
		printf("%.2f\n", res);
	}
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<string> vstring;

struct Edge{int to,from,cost;};

template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

#define rep(i,n) for(int i=0;i<(n);++i)
#define rep0(i,n) for(i=0;i<(n);++i)
#define repn(i,m,n) for(int i=(m);i<=(n);++i)
#define all(n) n.begin(),n.end()
#define sz(n) ((int)(n).size())
#define mp make_pair
#define PUTLINE cout<<"LINE:"<<__LINE__<<endl;

const int INF = 2147483647;
const double EPS = 1e-10;
const double PI = acos(-1.0);

const int dx[]={1,-1,0,0,1,-1,1,-1,0};
const int dy[]={0,0,1,-1,1,-1,-1,1,0};

double g[110][110];
double dp[110][110];

int main() {
	int n,m;
	for(;;){
		cin>>n>>m;
		if(n==0&&m==0)break;
		rep(y,n)rep(x,n)cin>>g[y][x];
		rep(y,m)rep(x,n)dp[y][x]=0;
		rep(i,n)dp[0][i]=1;
		repn(i,1,m-1)rep(j,n)rep(k,n)chmax(dp[i][j],dp[i-1][k]*g[k][j]);
		double res=0;
		rep(i,n)chmax(res,dp[m-1][i]);
		int r=(res+0.005)*100;
		printf("%d.%02d\n",r/100,r%100);
	}
	return 0;
}

C++: #include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,b,n) for(int i=b;i<n;i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int n,m;
const int MAX_N =120;
const int MAX_M =120;
double dp[MAX_N][MAX_M];//dp[i][j]:=直前にjを与え、i回目に肥料を与えたときの最大の成長
double memo[MAX_N][MAX_N];
int main(){
	while(cin>>n>>m,n||m){
		for(int i =0;i <MAX_N;i++){
			for(int j =0;j <MAX_N;j++){
				dp[i][j] =0;
				memo[i][j]=0;
			}
		}
		rep(i,n){
			rep(j,n){
				cin>>memo[i][j];
			}
		}
		rep(i,n)dp[1][i] =1;
		double ans =0;
		for(int i =1;i <m;i++){
			for(int j =0;j <n;j++){//直後
				for(int k =0;k <n;k++){//直前
					dp[i+1][j] =max(dp[i+1][j],dp[i][k]*memo[k][j]);
					if(dp[i+1][j]>ans){
						ans =dp[i+1][j];
					}
				}
			}
		}
		ans +=0.005;
		ans =ans*100;
		ans =(int)ans;
		ans =(double)ans/100;
		printf("%.2f\n",ans);
	}
	return 0;
}