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 <stdio.h>
#include <algorithm>
using namespace std;

int main()
{
	double memo1[100] = {};
	double memo2[100] = {};
	double data[100][100];
	int n, m;

	while (true)
	{
		cin >> n >> m;
		if (n + m == 0) return 0;

		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < n; j++)
			{
				cin >> data[i][j];
			}
			memo1[i] = 1.0;
		}

		for (int i = 0; i < m - 1; i++)
		{
			for (int j = 0; j < n; j++)
			{
				for (int k = 0; k < n; k++)
				{
					memo2[k] = max(memo2[k], memo1[j] * data[k][j]);
				}
				memo1[j] = 0;
			}
			swap(memo1, memo2);
		}

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

	return 0;
}

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

const int MAX_N = 100, MAX_M = 100;
const double EPS = 1e-10;

int n,m;
double g[MAX_N][MAX_N];
double dp[MAX_M][MAX_N]; //dp[cnt][prev]

double rec(int cnt, int prev)
{
    if(dp[cnt][prev] > 0.0)
        return dp[cnt][prev];

    if(cnt == 0)
        return dp[0][prev] = 1.0;
    
    double tmp, ret = 0.0;
    for(int i = 0; i < n; i++) {
        tmp = rec(cnt - 1, i) * g[prev][i];
        if(ret < tmp) 
            ret = tmp;
    }

    return dp[cnt][prev] = ret;
}

int main()
{
    while(cin >> n >> m && n) {
        for(int i = 0; i < n; i++)
            for(int j = 0; j < n; j++) 
                cin >> g[i][j];

        for(int i = 0; i < m; i++) 
            for(int j = 0; j < n; j++) 
                dp[i][j] = -1.0;

        double ans = 0.0, tmp;
        for(int i = 0; i < n; i++) {
            tmp = rec(m - 1, i);
            if(ans < tmp)
                ans = tmp;
        }

        ans = (double)(int)(ans * 100.0 + 0.5) / 100.0;
        printf("%.2f", ans);
    }
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;

#define TT template<typename T>
#define ET(T) typename T::value_type
TT inline T sq(T x){return x*x;}
TT inline T In(){T x;cin>>x;return x;}
TT inline int ubnd(T&v,ET(T) x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT inline int lbnd(T&v,ET(T) x){return lower_bound(begin(v),end(v),x)-begin(v);}
TT inline void sort(T&v){sort(begin(v),end(v));}
TT inline void revs(T&v){reverse(begin(v),end(v));}
TT inline void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT inline void inpt(T&v,int n,function<ET(T)()>f=In<ET(T)>){for(v.reserve(n);n--;v.emplace_back(f()));}
TT inline void show(T&v,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),cout<<x;cout<<e;}
#undef TT
#undef ET

inline void fast_io(){ios::sync_with_stdio(0); cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline string instr(){string x;cin>>x;return x;}
inline ll pow_mod(ll a, ll k, ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a, ll p){return pow_mod(a,p-2,p);}

const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = 1000000000;

int main()
{
  int n, m;
  while (cin >> n >> m, n){
    ld table[128][128];
    for (int i = 0; i < n; i++){
      for (int j = 0; j < n; j++){
        cin >> table[i][j];
      }
    }
    ld dp[128][128];
    for (int i = 0; i <= m; i++){
      for (int j = 0; j < n; j++){
        dp[i][j] = 0;
      }
    }
    for (int i = 0; i < n; i++){
      dp[1][i] = 1.0;
    }
    for (int i = 2; 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("%.2Lf\n", *max_element(dp[m], dp[m] + n));
  }
  return (0);
}

// priority_queue queue deque front top push pop map set stringstream max_element min_element insert count find get tie make_tuple

C++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

using vvd = V<vd>;

main {
  int n, m;
  while (cin >> n >> m, n) {
    vvd g(n, vd(n));
    cin >> g;
    vvd dp(m, vd(n, 1.0));
    loop(i, 1, m) rep(j, n) {
      double maxi = -INF;
      rep(k, n) cmax(maxi, dp[i - 1][k] * g[k][j]);
      dp[i][j] = maxi;
    }
    cout << prec(2) << *max_element(all(dp.back())) << endl;
  }
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int n,m;
double ans;
double dp[101][101];
double up[101][101];
int main(void){
	for(int i=1;i<=100;i++){
		up[i][0]=1.0;
	}
	while(1){
		memset(dp,0,sizeof(dp));
		ans=1;
		cin >> n >> m;
		if(n==0 && m==0)break;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				cin >> up[j][i];
			}
		}
		dp[0][0]=1;
		for(int i=1;i<=m;i++){
			for(int j=1;j<=n;j++){
				for(int k=0;k<=n;k++){
					dp[i][j]=max(dp[i][j],dp[i-1][k]*up[j][k]);
				}
				ans=max(ans,dp[i][j]);
			}
		}
		printf("%0.2f\n",ans);
	}
    return 0;
}