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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

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

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define rep(i,x) for(int i=0;i<(x);++i)
#define rep1(i,x) for(int i=1;i<=(x);++i)
#define rrep(i,x) for(int i=(x)-1;i>=0;--i)
#define rrep1(i,x) for(int i=(x);i>=1;--i)
#define FOR(i,a,x) for(int i=(a);i<(x);++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T get(){T a;cin>>a;return a;}
template<typename T>T rev(T a){reverse(all(a));return a;}
template<typename T>istream&operator>>(istream&is,vector<T>&vec){rep(i,vec.size())is>>vec[i];return is;}
template<typename T>vector<T>&sort(vector<T>&a){sort(all(a));return a;}

const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;

double table[100][100];

double dp[100][100]; // dp[times][cur]

signed main()
{
	int N, M;
	
	while (cin >> N >> M, N || M) {
		memset(dp, 0, sizeof(dp));

		rep(i, N) rep(j, N) cin >> table[i][j];

		rep(i, N) 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][k] * table[k][j]);
                }
			}
		}

        printf("%.2f\n", *max_element(dp[0], dp[M]));
	}
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;

double dp[2][111];
double g[111][111];

int main(){
    int n,m;
    while(cin >> n >> m && n){
        rep(i,n)rep(j,n) cin >> g[i][j];
        rep(i,111) dp[0][i] = 1;
        rep(i,111) dp[1][i] = 0;
        m--;
        rep(i,m){
            auto cur = dp[i&1], nx = dp[(i&1)^1];
            rep(i,111) nx[i] = 0;
            rep(i,n){ // cur
                rep(j,n){ // use
                    nx[j] = max(nx[j], cur[i]*g[i][j]);
                }
            }
            // rep(i,m) cout << nx[i] << " ";
            // cout << endl;
        }
        double ans = 0;
        rep(i,111) ans = max(ans, dp[m&1][i]);
        ans *= 100;
        int d = (int)(ans)%10;
        ans = floor(ans);
        if(d >= 5) ans += 1;
        ans /= 100;
        printf("%.2lf\n", ans);
    }
}

C++: #include <iostream>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int n,m;
	while(cin >> n >> m , n){
		double dp[101][101] = {0};
		double rate[101][101] = {0};
		rep(i,n)rep(j,n)
			cin >> rate[i][j];
		rep(i,n)dp[0][i] = 1.0;
		rep(x,m-1){
			rep(i,n)
				rep(j,n)
					dp[x+1][j] = max(dp[x][i]*rate[i][j],dp[x+1][j]);
		}
		double ans = 0;
		rep(i,n) ans = max(ans,dp[m-1][i]);
		printf("%.2lf\n",ans);
	}
}

C++: #include<cstdio>
#include<algorithm>

using namespace std;

int main(){
	static double table[100][100];
	double memo[100],next[100];
	for(int n,m;scanf("%d%d",&n,&m),n;){
		for(int i=0;i<n;i++)for(int j=0;j<n;j++)	scanf("%lf",table[i]+j);

		for(int i=0;i<n;i++)	memo[i]=1,next[i]=0;
		for(int t=1;t<m;t++){
			for(int i=0;i<n;i++)for(int j=0;j<n;j++){
				next[j]=max(next[j],table[i][j]*memo[i]);
			}
			for(int i=0;i<n;i++)	memo[i]=next[i];
		}

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

	return 0;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

ll n,m;
int f(int x,int y){
  return x + y * n;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  while(cin >> n >> m && n+m){
    vector<vector<double>> v(n,vector<double>(n));
    rep(i,n){
      rep(j,n){
        cin >> v[i][j];
      }
    }
    vector<vector<double>> dp(m+1,vector<double>(n,0));
    rep(i,n){
      dp[0][i] = 1.0;
    }
    rep(i,m){
      rep(j,n){
        rep(k,n){
          dp[i+1][k] = max(dp[i+1][k],dp[i][j] * v[j][k]);
        }
      }
    }
    double ans = 0;
    rep(i,n){
      ans = max(ans,dp[m-1][i]);
    }
    fcout(10) << ans << endl;
  }
  return 0;
}