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

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

typedef long long LL;
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;

template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline void print_vec(const std::vector<T> &v) { for (int i = 0; i < v.size(); ++i) {  if (i != 0) {std::cout << " ";} std::cout << v[i];} std::cout << "\n"; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
template<class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
template<class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); }

const int INF = 1L << 30;
const double EPS = 1e-9;
const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy4 = { 0, 1, 0, -1 }, dx4 = { 1, 0, -1, 0 };    // 4近傍（右, 下, 左, 上）
const std::vector<int> dy8 = { 0, -1, 0, 1, 1, -1, -1, 1 }, dx8 = { 1, 0, -1, 0, 1, 1, -1, -1 };

using namespace std;

int main() {
    cin.tie(0);
	ios::sync_with_stdio(false);

    while (true) {
        int N, M;
        cin >> N >> M;
        if (N == 0 and M == 0) {
            break;
        }

        vector<vector<double>> f(N, vector<double>(N));
        FOR(i, 0, N) {
            FOR(j, 0, N) {
                cin >> f[i][j];
            }
        }

        vector<vector<double>> dp(M + 10, vector<double>(N, 0));
        FOR(j, 0, N) {
            dp[0][j] = 1.0;
        }

        FOR(i, 0, M) {
            FOR(j, 0, N) {
                FOR(k, 0, N) {
                    dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] * f[j][k]);
                }
            }
        }

        double ans = 0.0;
        FOR(j, 0, N) {
            ans = max(ans, dp[M - 1][j]);
        }
        cout << fixed << setprecision(2) << round(ans * 1000) / 1000 << endl;

    }

	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

double table[100][100];


int main(){
	int n, m ;
	while(cin >> n >> m , n){
		rep(i,n)rep(j,n)cin >> table[i][j];
		
		double dp[100][100][2] = {{0.0}};
		
		rep(i,n)dp[0][i][0] = 1.0;
		
		bool c = false;
		
		rep(i,m-1){
			rep(j,n){
				rep(k,n){
					dp[i+1][j][c^1] = max(dp[i+1][j][c^1] , dp[i][j][c] * table[j][k]);
				}
			}
			c ^= 1;
		}
		double ret = 0;
		rep(i,n){
			ret = max(ret,dp[m-1][i][c]);
		}
		long long out = (ret * 100.0);
		printf("%.2lf\n",out/100.0);
	}
	
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

double table[100][100];
double dp[101][100];

int main(){
  int n,m;

  while(scanf("%d%d",&n,&m), n+m){
    REP(i,n) REP(j,n) scanf("%lf",&table[i][j]);
    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][k] = max(dp[i+1][k], dp[i][j] * table[j][k]);

    double ans = 0.0;
    REP(i,n)
      ans = max(ans, dp[m-1][i]);

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

  return 0;
}

C++: #include<stdio.h>
#include<string.h>
#define M(a,b)a>b?a:b
#define R(i,b)for(i=0;i<b;i++)
double C[100][100],P[100],Q[100],A;int n,m,i,j,k;int s(){R(i,n)P[i]=1;R(k,m-1){R(i,n){Q[i]=0;R(j,n)Q[i]=M(Q[i],P[j]*C[j][i]);}memcpy(P,Q,n*8);}A=0;R(i,n)A=M(A,P[i]);}main(){while(scanf("%d%d",&n,&m)&&n&&m){R(i,n)R(j,n)scanf("%lf",&C[i][j]);s();printf("%.2lf\n",A);}}

C++: #include <bits/stdc++.h>

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplece_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define Edge pair< i_i, int>
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define vd vector<double>
#define vvd vector< vd >
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign
 
signed main()
{
    int2(a, b);
    while (a) {
        vvd table(a, vd(a));
        rep(i, a) { rep(j, a) {
            cin >> table[i][j];
        } }

        vvd dp(b, vd(a, 0.0));
        rep(i, a) {
            dp[0][i] = 1.0;
        }
        rep(i, b-1) {
            rep(j, a) {
                rep(k, a) {
                    dp[i+1][k] = max(dp[i+1][k], 
                            dp[i][j] * table[j][k]);
                }
            }
        }
            
        double ans = 0.0;
        rep(i, a) {
            ans = max(dp[b-1][i], ans);
        }
        long ret = round(ans * 100);
        printf("%.2lf\n", (double)ret / 100);
        cin >> a >> b;
    }
    return 0;
}