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 <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>
#include <fstream>
#include <cassert>
using namespace std;

//common

typedef int  i32;
typedef long long i64,ll;
typedef long double ld;

#define BR "\n"
#define ALL(c) (c).begin(),(c).end()
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,l,r) for(int i=(int)l;i<(int)(r);++i)
#define EACH(it,o) for(auto it = (o).begin(); it != (o).end(); ++it)
#define IN(l,v,r) ((l)<=(v) && (v)<(r))

//config
//#define NDEBUG
//#define INF 1<<30
//#define EPS 1e-8
//const ll MOD =100000007;

//debug
#ifdef NDEBUG
#define DUMP(x)
#define DUMPLN(x)
#define DEBUG(x)
#define DEBUGLN(x)
#define LINE()
#define LINELN()
#define CHECK(exp,act)
#define STOP(e)
#else
#define DUMP(x)  cerr << #x << " = " << (x)
#define DUMPLN(x)  DUMP(x) <<endl
#define DEBUG(x) DUMP(x) << LINE() << " " << __FILE__
#define DEBUGLN(x) DEBUG(x)<<endl
#define LINE()    cerr<< " (L" << __LINE__ << ")"
#define LINELN()    LINE()<<endl
#define CHECK(exp,act)  if(exp!=act){DUMPLN(exp);DEBUGLN(act);}
#define STOP(e)  CHECK(e,true);if(!(e)) exit(1);
#endif

template<class T> inline string toString(const vector<T>& x) {
	stringstream ss;
	REP(i,x.size()){
		if(i!=0)ss<<" ";
		ss<< x[i];
	}
	return ss.str();
}

template<class T> inline string toString(const vector<vector<T> >& map) {
	stringstream ss;
	REP(i,map.size()){
		if(i!=0)ss<<BR;
		ss<< toString(map[i]);
	}
	return ss.str();
}
template<class K,class V>  string toString(map<K,V>& x) {
	string res;stringstream ss;
	for(auto& p:x)ss<< p.first<<":" << p.second<<" ";
	return ss.str();
}

string BITtoString(int bit){
    stringstream ss;
    while(bit!=0){ss<<(bit%2);bit/=2;}
    string res=ss.str();reverse(ALL(res));
    return res;
}

template<typename T,typename V> inline T pmod(T v,V MOD){
	return (v%MOD+MOD)%MOD;
}
#define nextInt(n) scanf("%d",&n)
#define defInt(n) int n;nextInt(n)
#define nextLong(n) scanf("%lld",&n)
#define defLong(n) ll n;nextLong(n)
#define nextDouble(n) scanf("%lf",&n)

class Main{
public:

	int N,M;
	void run(){
	//	ifstream cin("in");
	//	ofstream cout( "out" );	
        
        while(true){
            nextInt(N);nextInt(M);
			if(N==0)break;

			vector<vector<double> > gs(N,vector<double>(N));
			REP(i,N)REP(j,N)nextDouble(gs[i][j]);

			vector<vector<double>> dp(M,vector<double>(N,0));
			//初回
			fill(ALL(dp[0]),1);

			for(int c=1;c<M;c++){
				REP(i,N)REP(j,N){
					dp[c][i]=max(dp[c][i],dp[c-1][j]*gs[j][i]);
				}
			}

			double Mv=0;
			REP(i,N)Mv=max(Mv,dp[M-1][i]);

			cout <<round(Mv*100)/100<<endl;
		}
	}
};
int main(){
	cout <<fixed<<setprecision(2);
	ios::sync_with_stdio(false);
	Main().run();
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n,m;
  while(cin>>n>>m,n+m){
    vector<vector<double> > d(n,vector<double>(n));
    vector<double> now(n,1),past(n,1);
  
    rep(i,n)rep(j,n)cin>>d[i][j];
    rep(times,m-1){
      rep(i,n){
	rep(j,n){
	  // i is past , j is now
	  now[j] = max(now[j],past[i] * d[j][i]);
	}
      }
      //      rep(i,now.size())cout<<now[i]<<" ";cout<<endl;
      past = now;
    }
    double ret = -1;
    rep(i,now.size())ret=max(ret,now[i]);
    printf("%.2f\n",ret);
  }
  
  
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

typedef unsigned long long ull;

#define pb push_back
#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

int main(){
    int n, m;
    while(cin >> n >> m, n+m){
        vector<vector<double> > v;
        rep(i, n){
            vector<double> d; double p;
            rep(j, n){cin >> p; d.pb(p);}
            v.pb(d);
        }

        double dp[110][110];
        memset(dp, 0, sizeof(dp));
        rep(i, n) 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]*v[k][j]);
                }
            }
        }
        double ma = -1.0;
        rep(i, n) ma = max(ma, dp[m-1][i]);
        printf("%.2f\n",ma);
    }
}

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()
{
	double T[128][128], dp[128][128];
	int L[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, 0, sizeof(dp));
		fill(dp[0], dp[0]+m, 1.0);

		for(int i = 1; i < n; i++)
		{
			for(int j = 0; j < m; j++)
			{
				for(int k = 0; k < m; k++)
				{

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

		double res = 0; 
		for(int i = 0; i < m; i++)
		{
			res = max(res, dp[n-1][i]);
		}

		printf("%.2f\n",res);
	}
}

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

int main(){
  int n,m;
  double In;
 
  while(cin >> n >> m && n && m){
    vector<double> matrix[n];
  
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	cin >> In;
	matrix[i].push_back(In);
      }
    }
    double dp[n+1][n+1];//選んだもの、回数
    for(int i=0;i<=n;i++){
      dp[i][0] = dp[i][1] = 1.0; 
      for(int j=2;j<=n;j++){
	dp[i][j] = -1.0;
      }
    }

    for(int i=0;i<n;i++){
      for(int j=2;j<=m;j++){
	for(int k=0;k<n;k++){
	  dp[i][j] = max(dp[i][j],dp[i][j-1]*matrix[i][k]);
	}
      }
    }
    double ans = -1;
    for(int I=0;I<n;I++)ans = max(ans,dp[I][m]);
    printf("%.2f\n",ans);

  }
  return 0;
}