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 <algorithm>
#include <map>
#include <vector>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define IREP(it,array) for(vector<int>::iterator it=array.begin(); it!=array.end(); ++it)
#define PREP(it,array) for(vector<P>::iterator it=array.begin(); it!=array.end(); ++it)
#define SREP(it,array) for(vector<string>::iterator it=array.begin(); it!=array.end(); ++it)

#define MP       make_pair
#define PB       push_back
#define ALL(x)   (x).begin(),(x).end()

const int INF = 1<<29;
const double EPS = 1e-9;
double zero(double d){
  return d < EPS ? 0.0 : d;
}

typedef long long LL;
typedef pair<int,int> P;


int main()
{
  cout.setf(ios::fixed, ios::floatfield);
  cout.precision(2);

  int n,m;
  while( cin>>n>>m, n ){
    double g[n][n];
    REP(i,n){
      REP(j,n){
	double t;
	cin >> t;
	g[i][j] = t;
      }
    }

    double dp[m+1][n];
    memset( dp, 0, sizeof(dp) );
    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][k] * g[k][j] );
      }
    }
    
    double res=0.0;
    REP(i,n){
      res = max( res, dp[m-1][i] );
    }

    cout << res << endl;
  }


  return 0;
}

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

int main(){
  int n, m;
  double g[100][100];
  double dp[100][100]; //dp[i][j]:i番目までで前に肥料jを与えたときの最大の苗木長

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

    fill_n( *dp, 100 * 100, 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][k] = max( dp[i][k], dp[i - 1][j] * g[j][k]);
        }
      }
    }
    cout << fixed << setprecision(2) << *max_element( dp[m - 1], dp[m] + n) << endl;
  }
  return 0;
}

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

C++: #include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<utility>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<set>
 
using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+9
#define EPS 1e-9
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = j; i < (k); i++)
typedef long long ll;
double fert[128][128];
double dp[128][128];
int main(){
    int n,m;
    while(scanf("%d%d",&n,&m),(n|m)){
        memset(dp,0,sizeof(dp));
        rep(i,n)rep(j,n)scanf("%lf",&fert[i][j]);
        rep(i,m){
            rep(j,n){
                bool flg = false;
                if(i == 0)dp[i][j] = 1.0;
                else{
                    rep(k,n){
                        dp[i][j] = (!flg) ? dp[i-1][k] * fert[k][j] : max(dp[i][j],dp[i-1][k] * fert[k][j]);
                        flg = true;                    
                    }
                }
            }
        }
        double res = -1.0;
        rep(i,n){
            res = max(res,dp[m-1][i]);
        }  
        printf("%.2lf\n",res);
    }
    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <utility>
#include <set>
#include <cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pi acos(-1)
#define all(v) v.begin(),v.end()
#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))
using namespace std;
typedef pair<int,int> point;
typedef complex<double> P;
typedef long long ll;

const double eps = 1e-8;
const double INF = 1e12;


double dot(P a,P b){
	return a.real()*b.real()+a.imag()*b.imag();
}
double cross(P a,P b){
	return a.real()*b.imag()-a.imag()*b.real();
}

bool is_orthogonal(P a1,P a2,P b1,P b2){
	return EQ(dot(a1-a2,b1-b2),0.0);
}
bool is_parallel(P a1,P a2,P b1,P b2){
	return EQ(cross(a1-a2,b1-b2),0.0);
}

bool is_point_on_line(P a,P b,P c){
	return EQ(cross(b-a,c-a),0.0);
}

bool is_point_on_linesegment3(P a,P b,P c){
	//|a-c| + |c-b|<=|a-b| ???????????????
	return (abs(a-c)+abs(c-b)<abs(a-b)+EPS);
}

double distance_l_p(P a,P b,P c){
	return abs(cross(b-a,c-a))/abs(b-a);
}


double distance_ls_p(P a,P b,P c){
	if(dot(b-a,c-a)<EPS)return abs(c-a);
	if(dot(a-b,c-b)<EPS)return abs(c-b);
	return abs(cross(b-a,c-a))/abs(b-a);
}

int main(){
	int n,m;
	while(1){
		cin>>n>>m;
		if(n==0 && m==0)break;
		double rate[n][n];
		double nobi[m][n];
		rep(i,n){
			nobi[0][i]=1;
			rep(j,n){
				cin>>rate[i][j];
			}
		}
		loop(i,1,m){
			rep(j,n){
				rep(k,n){
					if(k==0)nobi[i][j]=nobi[i-1][k]*rate[k][j];
					else nobi[i][j]=max(nobi[i][j],nobi[i-1][k]*rate[k][j]);
				}
			}
		}
		double ans=-1;
		rep(i,n){
			ans=max(ans,nobi[m-1][i]);
		}
		printf("%.2f\n",ans);
	}
	return 0;
}