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 <algorithm>
using namespace std;
int main()
{
	int n, m;
	while(scanf("%d %d\n", &n, &m), n || m){
		long double g[n][n];
		/* dp[a][b]??????a?????????b?????\?????????????????????a?????§????????????????????§??? */
		long double dp[m][n];
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				scanf("%Lf", &g[i][j]);
			}
		}
		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[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] * g[k][j]);
				}
			}
		}
		long double res = 0;
		for(int i = 0; i < n; i++){
			res = max(res, dp[m - 1][i]);
		}
		printf("%.2Lf\n", res);
	}
	
	return 0;
}

C++: 
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int n, m;
double table[128][128], memo[128][128];
double maxGrow[128];

double rec(int p, int prv)
{
	if(p == m - 2) return maxGrow[prv];
	if(memo[p][prv] != -1) return memo[p][prv];
	
	int sld;
	double res = -1;
	for(int i = 0; i < n; i++)
	{
		double sub = rec(p + 1, i);
		
		if(res < sub)
		{
			res = sub;
			sld = i;
		}
	}
	
	return memo[p][prv] = table[prv][sld] * res;
}

int main()
{
	int i, j, k;
	while(cin >> n >> m && n)
	{
		rep(i, n) rep(j, n) cin >> table[i][j];
		
		rep(i, 128) maxGrow[i] = *max_element(table[i], table[i] + 128);
		double ans = 0;
		
		rep(i, n)
		{		
			rep(j, 128) rep(k, 128) memo[j][k] = -1;

			chmax(ans, rec(0, i));
		}
		
		printf("%.2f\n", ans);
	}	
}

C++: #include <stdio.h>
#include <string.h>
//
//ツテツスツトツサツブツミツッツシツδδ督づ崢づヲ
//
//
 
double max(double a, double b)
{
    if (a > b){
        return (a);
    }
    return (b);
}
 
int main(void)
{
    int i, j, k;
    int n, m;
    double gr[100][100];
    double dp[100][100];
    double ans;
    int upd;
    
    while (1){
        scanf("%d%d", &n, &m);
        
        if (n + m == 0){
            break;
        }
        
        for (i = 0; i < n; i++){
            for (j = 0; j < n; j++){
                scanf("%lf", &gr[i][j]);
            }
        }
        
        memset(dp, 0, sizeof(dp));
        for (i = 0; i < n; i++){
            dp[0][i] = 1;
        }
        
        ans = 0.00;
        for (i = 1; i < m; i++){
            for (j = 0; j < n; j++){
                upd = 0;
                for (k = 0; k < n; k++){
                    if (upd == 0){
                        dp[i][j] = dp[i - 1][k] * gr[k][j];
                        upd = 1;
                    }
                    else {
                        dp[i][j] = max(dp[i][j], dp[i - 1][k] * gr[k][j]);
                    }
                }
            }
        }
        
        for (i = 0; i < n; i++){
            ans = max(ans, dp[m - 1][i]);
        }
        
        printf("%.2lf\n", ans);
        
    }
    
    return (0);
}

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    while(true){
	int m,n;
	cin >> n >> m;
	vector< vector<double> > d(n,vector<double>(n,0.0) );
	if(n == 0 && m == 0) break;
	REP(i,n)REP(j,n) cin >> d[i][j];
	double ans = 0.0;
	vector<double> a(n);
	double dp[2][101];
	memset(dp,1,sizeof(dp));
	REP(i,101) dp[0][i] = 1;
	REP(i,m-1){
	    REP(j,101) dp[1][i] = 0;
	    REP(j,n){
		dp[1][j] = dp[0][j] * d[0][j];
		REP(k,n){
		    dp[1][j] = max(dp[1][j],dp[0][j] * d[k][j]);
		}
	    }
	    swap(dp[0],dp[1]);
	}
	REP(i,n) ans = max(dp[0][i],ans);
	int t = ans * 1000;
	t = t % 10;
	if(t >= 5) ans += 0.01;
	printf("%.2f\n",ans);
    }
    return 0;
}

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

using namespace std;

double mat[100][100];
double dp[2][100]; //[phase][prev]

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    while(true) {
        int N, M;
        cin >> N >> M;
        if(!N && !M) break;
        for(int i = 0; i < N; ++i) {
            for(int j = 0; j < N; ++j) {
                cin >> mat[i][j];
            }
        }
        for(int i = 0; i < N; ++i) {
            dp[0][i] = 1.0;
        }
        for(int i = 1; i < M; ++i) {
            const int cur = i & 1;
            const int prev = cur ^ 1;
            for(int j = 0; j < N; ++j) {
                dp[cur][j] = 0.0;
                for(int last = 0; last < N; ++last) {
                    dp[cur][j] = max(dp[cur][j], dp[prev][last] * mat[last][j]);
                }
            }
        }
        double ans = 0.0;
        for(int i = 0; i < N; ++i) {
            ans = max(ans, dp[(M-1)&1][i]);
        }
        printf("%.2f\n", ans);
    }
    return 0;
}