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 <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;

#define TT template<typename T>
#define ET(T) typename T::value_type
TT inline T sq(T x){return x*x;}
TT inline T In(){T x;cin>>x;return x;}
TT inline int ubnd(T&v,ET(T) x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT inline int lbnd(T&v,ET(T) x){return lower_bound(begin(v),end(v),x)-begin(v);}
TT inline void sort(T&v){sort(begin(v),end(v));}
TT inline void revs(T&v){reverse(begin(v),end(v));}
TT inline void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT inline void inpt(T&v,int n,function<ET(T)()>f=In<ET(T)>){for(v.reserve(n);n--;v.emplace_back(f()));}
TT inline void show(T&v,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),cout<<x;cout<<e;}
#undef TT
#undef ET

inline void fast_io(){ios::sync_with_stdio(0); cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline string instr(){string x;cin>>x;return x;}
inline ll pow_mod(ll a, ll k, ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a, ll p){return pow_mod(a,p-2,p);}

const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = 1000000000;

int main()
{
  int n, m;
  while (cin >> n >> m, n){
    ld table[128][128];
    for (int i = 0; i < n; i++){
      for (int j = 0; j < n; j++){
        cin >> table[i][j];
      }
    }
    ld dp[128][128];
    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[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] * table[k][j]);
        }
      }
    }
    printf("%Lf\n", *max_element(dp[m], dp[m] + n));
  }
  return (0);
}

// priority_queue queue deque front top push pop map set stringstream max_element min_element insert count find get tie make_tuple

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

using namespace std;
const int INF = 1000000;

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

double check(int i,int mm)
{
  if(i==-1)
    {
      double tmp=1.0;
      if(mm>0)
	for(int xx=0;xx<n;xx++)
	{
	  tmp=max(tmp,check(xx,mm-1));
	}
      return tmp;
    }
  else
    {
      if(mm<0)
	return -INF;
      else if(mm==0)
	return 1.0;
      else if(dp[i][mm]!=-1)
	return dp[i][mm];
      else
	{
	  double tmp=check(0,mm-1)*data[i][0];
	  for(int xx=1;xx<n;xx++)
	    {
	      tmp=max(tmp,check(xx,mm-1)*data[i][xx]);
	    }
	  dp[i][mm]=tmp;
	  return tmp;
	}
    }
}

int main()
{

  for(;cin>>n>>m,n;)
    {
      for(int i=0;i<100;i++)
	for(int mm=0;mm<100;mm++)
	  {
	    dp[i][mm]=-1.0;
	  }
      for(int i=0;i<m;i++)
	for(int j=0;j<m;j++)
	  {
	    double tmp;
	    cin>>tmp;
	    data[i][j]=tmp;
	  }
      double ans=check(-1,m);
      
      cout<< fixed<<setprecision(2)<< ans << endl;
      
    }
}

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);
    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 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<iomanip>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<vector>
#include<functional>

using namespace std;

#ifdef DEBUG
#define dprintf      printf
#define dout(x)      cout<<#x" = "<<(x)<<endl
#define darray(x,n)    {int i;rep(i,n)cout<<#x"["<<i<<"] = "<<*((x)+i)<<endl;}
#define dloop(i,s,g) for((i)=(s);(i)<(g);(i)++)
#define drep(i,n)    for((i)=0;(i)<(n);(i)++)
#define dstop()      scanf("%*c")
#else
#define dprintf      (1)?0:printf
#define dout(x)
#define darray(x,n)
#define dloop(i,s,g) if(1){}else
#define drep(i,n)    if(1){}else
#define dstop()      if(1){}else
#endif

#define F    first
#define S    second
#define pb   push_back
#define mp   make_pair

#define loop(i,s,g) for((i)=(s);(i)<(g);(i)++)
#define rep(i,n)    for((i)=0;(i)<(n);(i)++)
#define all(x)      (x.begin(),x.end())
#define in(T,...) T __VA_ARGS__; impl(__VA_ARGS__);
#define array(T,id,n) T id[n]; rep(i,n)cin>>id[i];

//#define int long long;
#ifndef int
#define INF  (0x7fffffff)
#else
#define INF (0x7fffffffffffffff)
#endif

typedef  long long           ll;
typedef  unsigned            ui;
typedef  unsigned long long  ull;
typedef  pair<int,int>       i_i;
typedef  pair<ll,int>        ll_i;
typedef  pair<ll,ll>         ll_ll;
typedef  pair<double,int>    d_i;
typedef  pair<double,double> d_d;

void impl(){};
template <typename T,typename... TS >
void impl(T &head,TS &... tail)
{
  cin>>head;
  impl(tail ...);
}

signed main(void)
{
  while(1)
    {
      int i,j,k;
      int n,m;
      double g[112][112]={};
      double dp[112][112]={};
      cin>>n>>m;
      if(!n)break;
      rep(i,n)
	rep(j,n)
	  cin>>g[i][j];
      rep(i,n)
	dp[i][0]=1;
      for(j=1;j<m;j++)
	rep(i,n)
	  {
	    double max=0.0;
	    rep(k,n)
	      max=dp[k][j-1]*g[k][i]>max?dp[k][j-1]*g[k][i]:max;
	    dp[i][j]=max;
	  }
      double max=0.0;
      rep(i,n)
	max=dp[i][n-1]>max?dp[i][n-1]:max;
      printf("%.2f\n",max);
    }
  return 0;
}

C++: #include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
double g[100][100],dp[100][100];
int main(){
    int n,m;
    while(scanf("%d%d",&n,&m),n||m){
        for(int i=0;i<n;i++)
            for(int j=0;j<m;j++)
                scanf("%lf",&g[i][j]);
        
        fill_n(dp[0],100,1.0);
        fill_n(dp[1],9900,0.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][k]*g[k][j]);

        printf("%.2f\n",*max_element(dp[m-1],dp[m-1]+n));
    }
    return 0;
}