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>

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", float(int(ans * 100 + 0.5)) / 100);
    }

    return 0;
}

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

int n , m ;
double table[110][110] ;
double memo[110][110] ;

double dp( int day , int p ){
	if( memo[day][p] != -1.0 ) return memo[day][p] ;
	if( day >= m ) return 1.0 ;
	
	double best = -100.0 ;
	for( int next=0 ; next < n ; next++ ){
		best = max( best , dp( day+1 , next ) * table[p][next] ) ;
	}
	
	return memo[day][p] = best ;
}

int main(){
	
	for( int i=0 ; i<101 ; i++ ){
		for( int j=0 ; j<101 ; j++ ){
			memo[i][j] = -1.0 ;
		}
	}
	
	while( cin >> n >> m , n ){
		for( int i=0 ; i<n ; i++ ){
			for( int j=0 ; j<n ; j++ ){
				cin >> table[i][j] ;
			}
		}
		for( int i=0 ; i<101 ; i++ ){
			for( int j=0 ; j<101 ; j++ ){
				memo[i][j] = -1.0 ;
			}
		}
		
		double ans = -100.0 ;
		for( int i=0 ; i<n ; i++ ){
			ans = max( ans , dp(1,i) ) ;
		}
		
		printf("%0.2lf\n",ans) ;
	}
	
return 0 ;
}

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

#define ll (long long)
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)


using namespace std;


int main(void){
    
    int drugnumber;
    int drugcounter;
    /* x????¨????,y?????´????????? */
    double drugeffect[120][120] = {0};
    int i,j,k,l;
    double max = 0;
    double answer[100] = {0};
    
    while(cin >> drugnumber >> drugcounter,drugnumber+drugnumber)
    {
        double combination[120][120] = {0};
        /*??£??\*/
        FOR(j, 1, drugnumber+1)
        FOR(i, 1, drugnumber+1)
        cin >> drugeffect[j][i];
        
        //cout << drugeffect[2][1];
        
        for(k = 1;k <= drugnumber; k++)
            combination[1][k] = 1.0;
        //cout << combination[1][2] << endl;
        
        /* j?????¬?????°,i????????°*/
        
        for(i = 1; i< drugcounter;i++)
            for(j = 1; j<= drugnumber;j++)
            {
                for(k = 1; k<=drugnumber;k++)
                {
                    if((combination[i][j] * drugeffect[j][k]) >= combination[i+1][k])
                        combination[i+1][k] = combination[i][j]*drugeffect[j][k];
                     //cout << combination[i+1][j] << " ";
                    /*
                     if((combination[j][i] * drugeffect[j][i]) >= combination[j][i])
                     combination[j][i+1] = combination[j][i] * drugeffect[j][i];
                     */
                }
            }
        
    
    for(i = 1 ; i<= drugnumber;i++)
        if(max <  combination[drugcounter][i])
            max = combination[drugcounter][i];
    
        answer[l] = max;
        max = 0;
        l++;
        
    }
    REP(i,l)
    printf("%.2f\n",answer[i]);
    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<double> > dp(m, vector<double>(n, 1.0));
		vector< vector<double> > data(n, vector<double>(n));
		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)
				{
					dp[i][j] = max(dp[i][j], dp[i - 1][k] * data[j][k]);
				}
			}
		}
		double maximum = 0;
		for(int i = 0; i < n; ++i)
		{
			maximum = max(maximum, dp[m - 1][i]);
		}
		if((int)(maximum * 1000) % 10 >= 5)
		{
			printf("%.2f\n", maximum + 0.01);
		}
		else
		{
			printf("%.2f\n", maximum);
		}
	}
}

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

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

using namespace std;

#define EPS pow(10, -9)

int main() {
	int n, m;
	while (cin >> n >> m) {
		if (n == 0 && m == 0) {
			break;
		}
		vector< vector<double> > hyou(n, vector<double>(n));
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cin >> hyou[i][j];
			}
		}
		vector< vector<double> > nae(m, vector<double>(n, 1.0));
		for (int i = 1; i < m; i++) {
			for (int j = 0; j < n; j++) {
				nae[i][j] = nae[i-1][0]*hyou[0][j];
				for (int k = 1; k < n; k++) {
					nae[i][j] = max(nae[i][j], nae[i-1][k]*hyou[k][j]);
				}
			}
		}
		double MAX = 0.0;
		for (int i = 0; i < n; i++) {
			MAX = max(MAX, nae[m-1][i]);
		}
		MAX += EPS;
		printf("%.2f\n", MAX);
	}
	return 0;
}

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;
}