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 <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define ALL(A)		(A).begin(),(A).end()
#define DUMP(A)    cout<<#A<<"="<<(A)<< endl
#define SIZE(A)    (int)((A).size())
using namespace std;
typedef long long ll;

int main(){
    int N,M;
    for(;;){
        double htoh[101][101];
        scanf("%d%d",&N,&M);
        if(N==0&&M==0) break;
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                scanf("%lf",&htoh[i][j]);
            }
        }
        double dp[2][101];
        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++){
                dp[i%2][j]=dp[(i-1)%2][0]*htoh[0][j];
                for(int k=0;k<N;k++){
                    dp[i%2][j]=max(dp[i%2][j],dp[(i-1)%2][k]*htoh[k][j]);
                }
            }
        }
        double ma=dp[(M-1)%2][0];
        for(int i=0;i<N;i++){
            ma=max(ma,dp[(M-1)%2][i]);
        }
        printf("%.2f\n",ma);
    }
}

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	cout << fixed << setprecision(2);
	while (1) {
		int N, M; cin >> N >> M;
		if (!N)break;
		vector<vector<ld>>field(N+1, vector<ld>(N));
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				cin >> field[i][j];
			}
			
		}
		for (int j = 0; j < N; ++j) {
			field[N][j] = 1;
		}
		vector<vector<ld>>dp(M + 1, vector<ld>(N+1));
		dp[0][N] = 1;
		for (int t = 0; t < M; ++t) {
			for (int pre = 0; pre <= N; ++pre) {
				for (int next = 0; next < N; ++next) {
					dp[t + 1][next] = max(dp[t + 1][next], dp[t][pre] * field[pre][next]);
				}
			}
		}
		ld ans = 0;
		for (int i = 0; i < N; ++i) {
			ans = max(ans, dp[M][i]);
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<math.h>
#include<stdio.h>
using namespace std;

int main(void){
	double dp[100][100];	// [回数][種類]
	double table[100][100];
	int N, T;

	while(true){
		cin >> T >> N;
		if( T == 0 && N == 0)
			break;
		for(int bef=0; bef<T; bef++)
			for(int cur=0; cur<T; cur++)
				cin >> table[cur][bef];

		// init
		for(int n=0; n<N; n++)
			for(int t=0; t<T; t++)
				dp[n][t] = n == 0 ? 1 : 0;
		
		// calc
		for(int n=0; n<N-1; n++){
			for(int tcur=0; tcur<T; tcur++){
				for(int taft=0; taft<T; taft++){
					dp[n+1][taft] = max(dp[n+1][taft], dp[n][tcur]*table[tcur][taft]);
				}
			}
		}

		// out calc
		double res = 0;
		for(int t=0; t<T; t++)
			res = max(dp[N-1][t], res);

		res = res * pow((double)10, 2);
		res = (double)(int)(res + 0.5);
		res = res * pow((double)10, -2);


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

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(cnt == 0)
        return dp[0][prev] = 1.0;

    if(dp[cnt][prev] > -1.0)
        return dp[cnt][prev];
    
    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++) 
                scanf("%lf", &g[i][j]);
        
        for(int i = 0; i < m; i++) 
            for(int j = 0; j < n; j++) 
                dp[i][j] = -1.1;
        

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

        printf("%.2lf", ans);
    }
}

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

int main(){
	int n, m;
	double dp[101][101], hiryou[101][101];
	while(cin >>n >>m){
		if(n == 0 && m == 0) break;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				cin >>hiryou[i][j];
			}
		}
		dp[0][0] = 1.0;
		dp[0][1] = 1.0;
		dp[0][2] = 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++){
					if(dp[i - 1][k] * hiryou[k][j] > dp[i][j]) dp[i][j] = dp[i - 1][k] * hiryou[k][j];
				}
			}
		}
		double ans = 0.0;
		for(int i = 0; i < n; i++){
			if(dp[m - 1][i] > ans) ans = dp[m - 1][i];
		}
		printf("%.2f\n", ans);
	}
	return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
using namespace std;
double dp[100][100],g[100][100];
int main(){
  int n, m;
  while(cin >> n >> m , n){
    for(int i = 0 ; i < n ; i ++ ){
      for(int j = 0 ; j < n ; j++ ){
	cin >> g[i][j];
      }
    }
    fill_n( dp[0], n, 1.0);
    fill_n( dp[1], 9900, 0);
    for(int i = 1 ; i < m ; i++ ){ //回数
      for(int prev = 0 ; prev < n ; prev++ ){ // prev
	for(int now = 0 ; now < n ; now++ ){ // now
	  dp[i][now] = max( dp[i][now], dp[i - 1][prev] * g[prev][now]);
	}
      }
    }
    cout << fixed << setprecision(2) << *max_element( dp[m - 1], dp[m - 1] + n ) << endl;
  }
}

C++: #include <iostream>
#include<iomanip>
#include<algorithm>
#define shosu(x) fixed<<setprecision(x)
using namespace std;

int n,m;
double ef[105][105];

double func(){
	double ans=0,dp[105][105]={0};
	for(int i=0;i<m;i++){
		dp[0][i]=1;
	}
	for(int i=1;i<n;i++){
		for(int j=0;j<m;j++){
			int tmp=0;
			for(int k=0;k<m;k++){
				tmp=max(tmp,dp[i-1][k]*ef[k][j]);
			}
			dp[i][j]=tmp;
		}
	}
	for(int i=0;i<m;i++){
		ans=max(ans,dp[n-1][i]);
	}
	return ans;
}

int main(){
	cout<<shosu(2);
	while(1){
		cin>>n>>m;
		if(n==0&&m==0) break;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cin>>ef[i][j];
			}
		}
		cout<<func()<<endl;
	}
}