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 <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define F first
#define S second
#define INF 1 << 30

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int main(){
  int n, m;
  double dp[128][128];
  double g[128][128];
  while(scanf("%d%d", &n, &m) && n+m){
    rep(i, n) rep(j, n) scanf("%lf", &g[i][j]);

      memset(dp, 0, sizeof(dp));
    rep(i, n) dp[i][0] = 1.0;

    /*    rep(i, n){
      rep(j, m) printf("%.2lf ", dp[i][j]);
      puts("");
      }*/

    REP(i, 1, m){
      rep(j, n){
	rep(k, n){
	  dp[j][i] = max(dp[j][i], dp[k][i-1]*g[k][j]);
	  //	  printf("%d %d %d %.2lf\n", i, j, k, g[k][j]);
	}
      }
      /*      rep(i, n){
	rep(j, m) printf("%.2lf ", dp[i][j]);
	puts("");
	}*/
    }

    /*    rep(i, n){
      rep(j, m) printf("%.3lf ", dp[i][j]);
      puts("");
      }*/
    double res = 0;
    rep(i, n) res = max(res, dp[i][m-1]);
    //    res *= 100;
    //    int tmp = (int)res + 0.5;
    //    res = (double)tmp / 100;
    printf("%.2lf\n", res);
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int main() {
  double f[101][101];
  double dp[101][101];
  int n,m;
  while (cin >> n >> m,n||m) {
    
    for ( int i = 0; i < n; i++ ) {
      for ( int j = 0; j < n; j++ ) {
	cin >> f[i][j];
      }
    }

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

    for ( int i = 0; i < n; i++ ) dp[0][i] = 1.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] = max( dp[i][j], dp[i-1][j] * f[j][k] );
	}
      }
    }
    printf ("%.2f\n", dp[m-1][n-1] );
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;



int main(){
while(true){
	int n, m;
	double g[205][205];
	double dp[205][205];
	cin >> n >> m;
	if(n == 0 && m == 0) return 0;
	std::memset(g, 0.0, sizeof(g));
	std::memset(dp, 0.0, sizeof(dp));
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			cin >> g[j][i];
		}
	}
	for(int i = 0; i < n; i++){
		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[j][k]);
			}
		}
	}
	double res = 0.0;
	for(int i = 0; i < n; i++){
		res = max(res, dp[m][i]);
	}
	printf("%.2lf\n",res);
}
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int m,n;
double a[100][100],b[100][100];
double f(int p,int q,double r){
  int i;
  double mx=0;
  if(p==m){
    mx=r;
  }else if(b[p][q]<r){
    b[p][q]=r;
    for(i=0;i<n;i++)
      mx=max(mx,f(p+1,i,r*a[q][i]));
    b[p][q]=0;
  }
  return mx;
}
int main(){
  int i,j;
  double mx;
  while(cin>>n>>m&&n+m){
    for(i=0;i<n;i++)
      for(j=0;j<n;j++)
	cin>>a[i][j];
    mx=0;
    for(i=0;i<n;i++)
      mx=max(mx,f(1,i,1));
    printf("%.2lf\n",mx);
  }
  return 0;
}

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

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;
const int INF = 1 << 30;

int main()
{
	long double T[128][128], dp[128][128];
	int n, m;

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

		for(int i = 0; i < n; i++)
		{
			for(int j = 0; j < n; j++)
			{
				cin >> T[i][j];
			}
		}
		
		memset(dp, -1, sizeof(dp));
	
		for(int i = 0; i < n; i++)
		{
			dp[0][i] = 1.0;
		}

		for(int i = 1; i < m; i++)
		{
			for(int j = 0; j < n; j++)
			{
				dp[i][j] = -1.0;
				for(int k = 0; k < n; k++)
				{
					//dp[i][j] : i回目で肥料kを使った時の最大の苗木の大きさ
					dp[i][j] = max(dp[i][j], dp[i-1][k]*T[k][j]);
				}
			}
		}

		long double res = -1; 
		for(int i = 0; i < n; i++)
		{
			res = max(res, dp[m-1][i]);
		}
	
		printf("%.2Lf\n",res);
	}
}

C++: #include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;

#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n) REP(i,0,n)

int n, m;
double sheet[100][100], dp[100][100];

double dfs(int et, int b) {
  if (et == m) return 1.0;
  if (dp[et][b] >= 0) return dp[et][b];
  
  double res = 0;
  rep(i,n) {
    res = max(res, sheet[b][i] * dfs(et+1, i));
  }
  return dp[et][b] = res;
}

void solve() {
  rep(i,n) rep(j,n) cin>>sheet[i][j];
  double res = -1;
  memset(dp, -1, sizeof dp);
  
  rep(i,n) {
    res = max(dfs(1, i), res);
  }
  printf("%.2lf\n", res);
}

int main (int argc, char const* argv[]) {
  while (cin>>n>>m, n||m) {
    solve();
  }
  return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <vector>
#include <cmath>

using namespace std;

void solve()
{
	int n, m;
	while(cin >> n >> m, n || m)
	{
		long double data[101][101];
		for(int i = 0; i < n; ++i)
		{
			for(int j = 0; j < n; ++j)
			{
				cin >> data[i][j];
			}
		}
		long double dp[101][101];
		for(int i = 0; i < m; ++i)
		{
			for(int j = 0; j < n; ++j)
			{
				dp[i][j] = 0;
			}
		}
		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)
			{
				for(int k = 0; k < n; ++k)
				{
					dp[i][j] = max(dp[i][j], dp[i - 1][k] * data[k][j]);
				}
			}
		}
		long double maximum = 0;
		for(int i = 0; i < n; ++i)
		{
			maximum = max(maximum, dp[m - 1][i]);
		}
		printf("%.2lf\n", maximum);
	}
}

int main()
{
	solve();
	return(0);
}