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 memo[100][100];
	double data[100][100];
	int n, m;

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

		for (int i = 0; i < n; i++){
			for (int j = 0; j < m; j++){
				memo[i][j] = -1;
				if (i == 0) memo[i][j] = 1.0;
			}
		}

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

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

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

	return 0;
}

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

using namespace std;

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define INF 1e9

int main(){
    while(true){
        int n,m;
        cin >> n >> m ;
        if(n==0 && m ==0)
            break;
        vector<vector<double>> bt(n,vector<double>(n));
        vector<vector<double>> dp(m,vector<double>(n,0.0));

        FOR(i,0,n){
            FOR(j,0,n){
                cin >> bt[i][j] ;
            }
            dp[0][i] = 1.0;
        }
        double ans = -1e10;
        FOR(i,0,m-1){
            FOR(j,0,n){
                FOR(k,0,n){
                    dp[i+1][j] = max(dp[i+1][j], dp[i][k] * bt[k][j]);
                    ans = max(ans, dp[i+1][j]);
                }
            }
        }

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

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

constexpr int MAX_NM = 100;

int main(){
    int N, M;
    float table[MAX_NM][MAX_NM]{}, dp[MAX_NM][MAX_NM]{};
    
    while(true){
        scanf("%d%d", &N, &M);
        if(N == 0 && M == 0){
            break;
        }
        
        for(int i = 0; i < N; ++i){
            dp[0][i] = 1;
            for(int j = 0; j < N; ++j){
                scanf("%f", &table[i][j]); // [prev][now]
            }
        }

        for(int i = 1; i < M; ++i){
            for(int j = 0; j < N; ++j){
                float max = 0;
                for(int k = 0; k < N; ++k){
                    max = std::max(max, dp[i - 1][k] * table[k][j]);
                }
                dp[i][j] = max;
            }
        }

        float ans = 0;

        for(int i = 0; i < N; ++i){
            ans = std::max(ans, dp[M - 1][i]);
        }
        printf("%.2f\n", ans);
    }

    return 0;
}

C++: #include<stdio.h>
#include<algorithm>
int main()
{
	int n,m,i,j,k;
	double t[100][100];
	while(scanf("%d%d",&n,&m),n)
	{
		double d[101][100]={0};
		for(i=0;i<n;++i)for(d[j=0][i]=1;j<n;++j)scanf("%lf",&t[i][j]);
		for(k=1;k<m;++k)
			for(i=0;i<n;++i)
				for(j=0;j<n;++j)
					d[k][j]=std::max(d[k][j],d[k-1][i]*t[i][j]);
		printf("%.2f\n",*std::max_element(d[m-1],d[m-1]+n));
	}
	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(2) << ans << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <vector>
#include <cmath>

using namespace std;

void solve()
{
	int n, m;
	while(cin >> n >> m, n || m)
	{
		vector< vector<long double> > dp(m, vector<long double>(n));
		vector< vector<long double> > data(n, vector<long double>(n));
		for(int i = 0; i < n; ++i)
		{
			for(int j = 0; j < n; ++j)
			{
				cin >> data[i][j];
			}
		}
		for(int i = 0; i < n; ++i)
		{
			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] * data[k][j]);
				}
			}
		}
		long double maximum = 0;
		for(int i = 0; i < n; ++i)
		{
			maximum = max(maximum, dp[m - 1][i]);
		}
		printf("%.2lf\n", maximum);
	}
}

int main()
{
	solve();
	return(0);
}