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 "stdio.h"

int n;
int m;
double p[100][100];
double dp[101][100];//i回目にjを使った時の最大の倍率

double ans = -1;

int max(int a,int b){if(a>b)return a;else return b;}

int main(){

	while(1){

		scanf("%d %d",&n,&m);

		if(n==0&&m==0){
			break;
		}

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

		ans = -1.0;

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

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

		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] * p[k][j]);
					if(i==m){
						ans = max(ans,dp[i][j]);
					}
				}
			}
		}

		ans += 0.00;


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

	}

	return 0;

}

C++: // 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

const pair<int, int> NIL(-1, -1);

double orig[110][110], mat[110][110], tmp[110][110];
 
signed main() {
    int N, M;
    while(cin >> N >> M, N) {
        for(int i=0; i<N; i++) {
            for(int j=0; j<N; j++) {
                cin >> mat[i][j];
                orig[i][j] = mat[i][j];
            }
        }

        cout << fixed << setprecision(2);
        if(M == 1) cout << 1.0 << endl;
        else {
            for(int k=0; k<M-2; k++) {
                fill(tmp[0], tmp[N], 0);
                for(int j=0; j<N; j++) {
                    double ma = -1;
                    for(int i=0; i<N; i++) {
                        chmax(ma, mat[i][j]);
                    }
                    for(int i=0; i<N; i++) {
                        chmax(tmp[j][i], orig[j][i] * ma);
                    }
                }
                swap(mat, tmp);
            }

            double ans = -1;
            for(int i=0; i<N; i++) {
                for(int j=0; j<N; j++) {
                    chmax(ans, mat[i][j]);
                }
            }
            cout << ans << endl;
        }
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)


int main(){
	int n, m ;
	while(cin >> n >> m , n){
		long double table[100][100];
		long double dp[2][100] = {{0.0}};
		
		
		rep(i,n)rep(j,n)cin >> table[i][j];
		rep(i,n)dp[0][i] = 1.0;
		bool sw = false;
		
		rep(i,m-1){ // kaisu 
			rep(j,n){ // chokuzen 
				rep(k,n){ // current
					dp[sw^1][k] = max(dp[sw^1][k] , dp[sw][j] * table[j][k]);
				}
			}
			sw ^= 1;
		}
		long double ret = 0;
		rep(i,n){
			ret = max(ret,dp[sw][i]);
		}
		printf("%.2Lf\n",ret);
	}
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int n,m,i,j,before,max_no[101]={};
double ans,dp,g[101][101]={};
double max_c[101]={};
double solve(){
  ans=0;
  for(i=0;i<n;i++){
    dp=1.0;
    before=i;
    for(j=0;j<m-1;j++){
      dp *= max_c[before];
      before=max_no[101];
    }
    if(ans<dp) ans=dp;
  }
  return ans;
}
//  for(j=0;j<n;j++){

int main(){
  while(cin>>n>>m, n||m){
    for(i=0;i<n;i++){
      max_c[i]=0;
      for(j=0;j<n;j++){
	cin>>g[i][j];
	if(max_c[i]<g[i][j]){
	  max_c[i]=g[i][j];
	  max_no[i]=j;
	}
      }
    }
    printf("%.2f\n",solve());
  }
  return 0;
}

C++: #include<iostream>
#include<cstdio>
#define INF 0
using namespace std;
int main(){
	int n,m;
	double t[200][200];
	while(cin>>n>>m,n||m){
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
				cin>>t[i][j];
		double dp[200][200];
		for(int i=0;i<=m;i++)
		for(int j=0;j<n;j++)
		dp[j][i]=INF;
		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++)
		for(int k=0;k<n;k++)
		dp[j][i]=max(dp[j][i],dp[k][i-1]*t[k][j]);
		double ans=INF;
		for(int i=0;i<n;i++)
		ans=max(ans,dp[i][m-1]);
		printf("%.2lf\n",ans);
		
	}
	return 0;
}

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

using namespace std;

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

int main() {
	while (cin >> n >> m, n * m) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				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++) {
				double M = 0;
				for (int k = 0; k < n; k++) {
					M = max(M, dp[i - 1][k] * grow[k][j]);
				}
				dp[i][j] = M;
			}
		}
		double ans = 0;
		for (int i = 0; i < n; i++) {
			ans = max(ans, dp[m - 1][i]);
		}
		cout << fixed << setprecision(2) << ans << endl;
		for (int i = 0; i < n; i++)for (int j = 0; j < n; j++)grow[i][j] = 0;
		for (int i = 0; i < m; i++)for (int j = 0; j < n; j++)dp[i][j] = 0;
	}
	return 0;
}

C++: #include<iostream>
#include<cmath>
using namespace std;
const double eps = 1.0e-10;
double eq(double a, double b){ //a==b
  return abs(b-a)<eps;
}
double gt(double a, double b){ //a>b
  return !eq(a,b) && a > b;
}
int main(){
  while(true){
    int n,m;
    double answer = -1;
    cin >> n >> m;
    if( n == 0 && m == 0 ) break;
    double table[n][n];
    for(int i = 0; i < n; ++i){
      for(int j = 0; j < n; ++j){
	cin >> table[i][j];
      }
    }
    int greed_color[n];
    double greed[n];
    for(int i = 0; i < n; ++i){
      greed_color[ i ] = i;
      greed[i] = 1.0;
    }
    for(int k = 0; k < m-1; ++k){
      for(int i = 0; i < n; ++i){
	int next_color = -1;
	double maximum = -1;
	for(int j = 0; j < n; ++j){
	  double t = greed[i] * table[ greed_color[i] ][ j ];
	  if( gt( t, maximum ) ){
	    maximum = t;
	    next_color = j;
	  }
	}
	greed[i] = maximum;
	greed_color[i] = next_color;
      }
    }
    
    for(int i = 0; i < n; ++i){
      if( gt( greed[i], answer ) )
	answer = greed[i];
    }
    printf("%.2lf\n",answer);

  }
  return 0;
}