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>
#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 <vector>
#include <algorithm>
#include <string>
#include <climits>
#include <stdio.h>

using namespace std;

typedef vector < double > VI;
typedef vector < VI > VVI;

int main () {
	int n, m;

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

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

		VVI g(n + 1, VI(n + 4, 0));
		VVI dp(n + 1, VI(m + 4, 0));

		for(int i = 1; i <= n; i++) {
			for(int j = 1; j <= n; j++) {
				cin >> g[i][j];
			}
		}

		for(int i = 0; i <= n; i++) {
			dp[0][i] = 1;
		}

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

		double ans = 0;

		for(int i = 0; i <= n; i++) {
			ans = max(ans, dp[n - 1][i]);
		}

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

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

int n, m;
double grow[100][100];
double dp[110][110];

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

    for(int i = 0; i < n; ++i) {
        dp[0][i] = 1.;
    }
    for(int i = 1; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            dp[i][j] = 0.;
        }
    }

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

    printf("%.2f\n", ((int)(*std::max_element(dp[m - 1], dp[m - 1] + n) * 100 + 0.5)) / 100.);


    }
}

C++: #include <bits/stdc++.h>

using namespace std;

#define MAX 150

int main()
{
    int N, M;
    while (cin >> N >> M, N) {
        double g[N][N];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                cin >> g[i][j];
            }
        }
        
        double dp[MAX][MAX];
        for (int i = 0; i < MAX; i++) {            
            for (int j = 0; j < MAX; j++) {
                dp[i][j] = (j == 0 ? 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[k][i+1] = max(dp[k][i+1],
                                       dp[j][i] * g[j][k]);
                }
            }
        }
        
        double res = 0;
        for (int i = 0; i < N; i++) {
            res = max(res, dp[i][M-1]);
        }
        printf("%.10f\n", res);
    }
    return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999

int main(){
    double g[110][110];
    rep(i,110)rep(j,110)g[i][j]=-1;
    int n,m;
    while(cin>>n>>m){
        if(n==0&&m==0)break;
        rep(i,n){
            rep(j,n){
                cin>>g[i][j];
            }
        }
    
    
        double dp[110][110];
        rep(i,110)rep(j,110)dp[i][j] = -1;
        rep(i,n)dp[1][i]=1.0;
    
        for(int i=2;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]*g[k][j]);
                }
            }
        }
        double ans = -1;
        rep(i,n){
            ans = max(ans,dp[m][i]);
        }
        printf("%.2lf\n",ans);
    }
}

C++: #include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>
  
int n, m;
double grow[100][100];
double dp[110][110];
  
int main() {
    while(std::cin >> n >> m, n + m) {
      
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            std::cin >> grow[i][j];
        }
    }
  
    for(int i = 0; i < n; ++i) {
        dp[0][i] = 1.;
    }
    for(int i = 1; i < m; ++i) {
        for(int j = 0; j < n; ++j) {
            dp[i][j] = 0.;
        }
    }
  
    for(int i = 1; i < m; ++i) {
        for(int j = 0; j < n; ++j) {
            for(int k = 0; k < n; ++k) {
                dp[i][j] = std::max(dp[i][j], dp[i - 1][k] * grow[k][j]);
            }
        }
    }
  
    printf("%.2lf\n", ((long long)(*std::max_element(dp[m - 1], dp[m - 1] + n) * 100 + 0.5)) / 100.);
  
  
    }
}

C++: #include<stdio.h>
double dat[100][100];
double dp[200][100];
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		for(int i=0;i<a;i++){
			for(int j=0;j<a;j++){
				scanf("%lf",&dat[i][j]);
			}
		}
		for(int i=0;i<a;i++)dp[0][i]=1;
		for(int i=1;i<b;i++){
			for(int j=0;j<a;j++){
				double max=0;
				for(int k=0;k<a;k++){
					if(max<dp[i-1][k]*dat[k][j])max=dp[i-1][k]*dat[k][j];
				}
				dp[i][j]=max;
			}
		}
		double ret=0;
		for(int i=0;i<a;i++){
			if(ret<dp[b-1][i])ret=dp[b-1][i];
		}
		printf("%.2lf\n",ret);
	}
}