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

using namespace std;
int n, m;
double cal(double g[][101]) {
  int i, j, k;
  double dp[m+1][n+1] = {};
  // double MAX = 0.0;
  double all_MAX = 0.0;
  
  for(i = 1; i <= n; i++) {
    dp[1][i] = 1.0;
  }
  
  for(i = 2; i <= m; i++)
    for(j = 1; j <= n; j++) {
      dp[i][j] = 0.0;
      for(k = 1; k <= n; k++) {
	dp[i][j] = max(dp[i-1][k]*g[k][j], dp[i][j]);
      }
    }
  
  for(i = 1; i <= m; i++) {
    for(j = 1; j <= n; j++){
      // cout << dp[i][j] << ' ';
      all_MAX = max(dp[i][j], all_MAX);
    }
    // cout << endl;
  }
  
  return all_MAX;
}

	  
int main() {
  int i, j;
  while(cin >> n >> m, n != 0 || m != 0) {
    double g[101][101] = {};
    
    for(i = 1; i <= n; i++)
      for(j = 1; j <= n; j++)
	cin >> g[i][j];
    printf("%.2f\n", cal(g));
  }
  
  return 0;
}

C++: #include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

#define reps(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reps(i,0,n)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const int INF = 1001001001;

int main()
{
	int n, m;
	while(scanf("%d%d", &n, &m), n){
		double g[100][100];
		rep(i, n) rep(j, n)
			scanf("%lf", &g[i][j]);
		
		double dp[100][100];
		fill(dp[0], dp[0]+n, 1.0);
		reps(i, 1, m){
			rep(j, n){
				dp[i][j] = 0.0;
				rep(k, n)
					dp[i][j] = max(dp[i][j], dp[i-1][k] * g[k][j]);
			}
		}
		
		printf("%.2f\n", *max_element(dp[m-1], dp[m-1]+n));
	}
	return 0;
}

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]);
					}
				}
			}
		}

		


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

	}

	return 0;

}

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

using namespace std;

#define EPS pow(10, -9)

int main() {
	int n, m;
	while (cin >> n >> m) {
		if (n == 0 && m == 0) {
			break;
		}
		vector< vector<long double> > hyou(n, vector<long double>(n));
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cin >> hyou[i][j];
			}
		}
		vector< vector<long double> > nae(m, vector<long double>(n, 1.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]);
				}
			}
		}
		long double MAX = 0.0;
		for (int i = 0; i < n; i++) {
			MAX = max(MAX, nae[m-1][i]);
		}
		MAX += EPS;
		MAX *= 100.0;
		if (MAX-(long double)((int)MAX) >= 0.5) {
			MAX += 1.0;
		} 
		MAX /= 100.0;
		printf("%.2Lf\n", MAX);
	}
	return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;

int main()
{
	double memo[100][100];
	double data[100][100];
	int n, m;

	while (true)
	{
		cin >> n >> m;
		if (n == 0) return 0;

		for (int i = 0; i < n; i++){
			for (int j = 0; j < m; j++){
				memo[i][j] = -1;
				if (i == 0) memo[i][j] = 1.0;
			}
		}

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

		for (int i = 1; i < m; i++){
			for (int j = 0; j < n; j++){
				for (int k = 0; k < n; k++){
					memo[i][k] = max(memo[i][k], memo[i - 1][j] * data[j][k]);
				}
			}
		}

		double Max = 0;
		for (int i = 0; i < n; i++)
		{
			Max = max(Max, memo[m - 1][i]);
		}
		printf("%.2f\n", Max);
	}

	return 0;
}

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

using namespace std;

#define ALL(co) co.begin(), co.end()
#define tpl(...) make_tuple(__VA_ARGS__)

typedef long long LL;
typedef pair<int, int> P; typedef pair<int, P> IP; typedef pair<P, P> PP;
typedef vector<int> Array; typedef vector<vector<int> > Array2;
typedef vector<LL> LArray; typedef vector<P> PArray; typedef vector<string> SArray;

const int INF = 1 << 29;
const LL LINF = 1LL << 60;

inline int getInt() { int itiv; return (cin >> itiv, itiv); }
template <typename T> void readAll(vector<T>& vec) { for (int i = 0, size = vec.size(); i < size; i++) cin >> vec[i]; }
template <typename T, typename U> void readAll(vector<pair<T, U> >& vec) { for (int i = 0, size = vec.size(); i < size; i++) cin >> vec[i].first >> vec[i].second; }
template < typename T > inline string toString( const T &a ){ ostringstream oss; oss << a; return oss.str(); };
inline bool between(int min, int max, int n) { return min <= n && n <= max; }
inline bool inRange(int begin, int end, int n) { return begin <= n && n < end; }
inline bool inRange(int size, int n) { return 0 <= n && n < size; }

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

int m, n;

int main(void)
{
	ios::sync_with_stdio(false);
	while(cin >> n >> m && n)
	{
		vector<vector<double> > table(n, vector<double>(n));
		for (int i = 0; i < n; i++)
		{
			readAll(table[i]);
		}
		
		vector<double> next(n);
		vector<double> now(n, 1);

		for (int i = 1; i < m; i++)
		{
			for (int j = 0; j < n; j++)
			{
				next[j] = now[0] * table[j][0];
				for (int k = 0; k < n; k++)
				{
					next[j] = max(next[j], now[k] * table[j][k]);
				}
			}
			now = next;
		}
		cout << (int)((*max_element(ALL(now)) + 0.005) * 100) / 100.0 << endl;
	}
	return 0;
}