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<cmath>
using namespace std;

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

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

double table[100][100];


int main(){
	int n, m ;
	while(cin >> n >> m , n){
		rep(i,n)rep(j,n)cin >> table[j][i];
		
		double dp[100][100] = {{0.0}};
		
		rep(i,n)dp[0][i] = 1.0;
		
		rep(i,m-1){
			rep(j,n){
				rep(k,n){
					dp[i+1][j] = max(dp[i+1][j] , dp[i][j] * table[j][k]);
				}
			}
		}
		double ret = 0;
		rep(i,n){
			ret = max(ret,dp[m-1][i]);
		}
		long long out = (ret * 100.0);
		printf("%.2lf\n",out/100.0);
	}
	
}

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
using namespace std;
double dp[100][100],g[100][100];
int main(){
  int n, m;
  while(cin >> n >> m , n){
    for(int i = 0 ; i < n ; i++ ) for(int j = 0 ; j < n ; j++ ) cin >> g[i][j];
 
    fill_n( dp[0], n, 1.0);
    fill_n( dp[1], 9900, 0.0);
    for(int i = 1 ; i < m ; i++ ){ //回数
      for(int prev = 0 ; prev < n ; prev++ ){ // prev
        for(int now = 0 ; now < n ; now++ ){ // now
          dp[i][now] = max( dp[i][now], dp[i - 1][prev] * g[prev][now]);
        }
      }
    }
    cout << fixed << setprecision(2) << *max_element( dp[m - 1], dp[m - 1] + n ) << endl;
  }
}

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

using namespace std;

int main() {
	int n, m;
	while (cin >> n >> m) {
		if (n == 0 && m == 0) {
			break;
		}
		vector< vector<double> > hyou(n, vector<double>(n));
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cin >> hyou[i][j];
			}
		}
		vector< vector<double> > nae(m, vector<double>(n, 1000.0));
		for (int i = 1; i < m; i++) {
			for (int j = 0; j < n; j++) {
				nae[i][j] = nae[i-1][0]*hyou[0][j];
				for (int k = 1; k < n; k++) {
					nae[i][j] = max(nae[i][j], nae[i-1][k]*hyou[k][j]);
				}
			}
		}
		int MAX = 0;
		for (int i = 0; i < n; i++) {
			MAX = max(MAX, (int)nae[m-1][i]);
		}
		int r = MAX%10;
		if (r >= 5) {
			MAX += (10-r);
		} else {
			MAX -= r;
		}
		double ans = (double)MAX/1000.0;
		printf("%.2f\n", ans);
	}
	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back
#define F first
#define S second

const int MAX=100;

int main(void)
{
  int n,m,i,j,k;
  double g[MAX][MAX],dp[MAX+1][MAX],res;//mñÚ,níÞ
  for(;;){
    scanf("%d%d",&n,&m); if(!n)break;
    memset(dp,0,sizeof(dp));
    rep(i,n)dp[0][i]=1.0;
    rep(i,n)rep(j,n)scanf("%lf",g[i]+j);
    rep(i,m)rep(j,n)rep(k,n){
      dp[i+1][k]=max(dp[i+1][k],dp[i][j]*g[j][k]);
    }
    res=0;
    rep(i,n)res=max(res,dp[m-1][i]);
    printf("%.2f\n",res);
  }
  return 0;
}

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

using namespace std;

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

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]);
		}
		int a = (ans + 0.05) * 1000;
		ans = a;
		ans /= 1000;
		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 <iomanip>
using namespace std;

double fig[100][100];
int n,m;

double serch(int kind,double point,int count){
	if(count==m)
		return point;
	double ans = 0.0;
	int num;
	for(int i=0;i<n;i++){
			if(ans < fig[kind][i]){
				ans = fig[kind][i];
				num = i;
			}
	}
	return serch(num,point*ans,count+1);
}
int main()
{
	while(cin >> n >> m){
		if(!n && !m)
			break;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cin >> fig[i][j];
			}
		}
		double ans = 0.0;
		for(int i=0;i<n;i++){
			ans = max(ans,serch(i,1.0,1));
		}
		cout << setprecision(2)<< fixed << ans << endl;
	}
	return 0;
}