Go: // n×nの成長度表に現れる数字を重複を許してm-1個選んで掛け合わせる時の最大値を求める
// ->掛け算型のDP

package main

import (
	"bufio"
	"os"
	"strings"
	"strconv"
		"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(3) << ans << endl;

    }

	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
using namespace std;
#define rep(i, j) for(int i = 0; i < j; i++)
#define f(i, k, j) for(int i = k; i < j; i++)
#define P pair<double, int>
const int INF = (1 << 26);

int n, m;
vector< vector<double> > vec, dp;

void solve(){
    f(j, 2, m + 1){
        vector<P> m;
        double bef = 0.0;
        rep(i, n){
            if(bef <= dp[i][j - 1]){
                m.push_back( P(dp[i][j - 1], i) );
                bef = dp[i][j - 1];
            }
        }
        rep(i, n) rep(k, m.size()) dp[i][j] = max(dp[i][j], m[k].first * vec[m[k].second][i]);
    }
}

int main(){
    while(cin >>n >>m && n != 0 && m != 0){
        vec = vector< vector<double> >(n);
        rep(i, n){
            vec[i] = vector<double>(n);
            rep(j, n) cin >>vec[i][j];
        }
        dp = vector< vector<double> >(n);
        rep(i, n){
            dp[i] = vector<double>(m + 1, 0.0);
            dp[i][0] = 1.0;
            dp[i][1] = 1.0;
        }

        solve();
        double ans = 0.0;
        rep(i, n) ans = max(ans, dp[i][m]);
        printf("%.2lf\n", ans);
    }
    return 0;
}

C++: #include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
int n, m; double e[111][111], dp[111][111];
int main() {
	while (cin >> n >> m, n | m) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) cin >> e[i][j];
		}
		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++) {
				dp[i][j] = 0.0;
				for (int k = 0; k < n; k++) {
					dp[i][j] = max(dp[i][j], dp[i - 1][k] * e[k][j]);
				}
			}
		}
		cout << fixed << setprecision(2) << *max_element(dp[m - 1], dp[m - 1] + n) << endl;
	}
	return 0;
}

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

using namespace std;

int main(){

	int n,m;
	while(cin>>n>>m&&!(n==0&&m==0)){
		double table[101][101];
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++)
				cin>>table[i][j];
		}
		double dp[2][101];
		fill(dp[0],dp[0]+101,1);
		fill(dp[1],dp[1]+101,0);

		double *prv=dp[0];
		double *nxt=dp[1];
		for(int k = 0; k < m-1; k++){
			for(int i = 0; i < n; i++){
				for(int j = 0; j < n; j++){
					nxt[i]=max(nxt[i],prv[j]*table[j][i]);
				}
			}
			swap(prv,nxt);
			fill(nxt,nxt+101,0);
		}

		double maxNum=0;
		for(int i = 0; i < n; i++){
			maxNum=max(maxNum,prv[i]);
		}
//		double ret = ((double)((int)(maxNum*100+0.5)))/100;
		double ret=maxNum;
		printf("%.2f\n",ret);
	}

	return 0;
}