Go: // n×nの成長度表に現れる数字を重複を許してm-1個選んで掛け合わせる時の最大値を求める
// ->掛け算型のDP

package main

import (
	"bufio"
	"os"
	"strings"
	"strconv"
	"log"
	"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 <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){
            for(int j = 0; j < N; ++j){
                scanf("%f", &table[i][j]); // [prev][now]
            }
        }

        for(int i = 0; i < M; ++i){
            for(int j = 0; j < N; ++j){
                if(i == 0){
                    dp[i][j] = 1;
                    continue;
                }
                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 <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;
const int INF = 1 << 30;

int main()
{
	long double T[128][128], dp[128][128];
	int n, m;

	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 >> T[i][j];
			}
		}
		
		memset(dp, -1, sizeof(dp));
	
		for(int i = 0; i < n; i++)
		{
			dp[0][i] = 1.0;
		}

		for(int i = 1; i < m; i++)
		{
			for(int j = 0; j < n; j++)
			{
				dp[i][j] = -1.0;
				for(int k = 0; k < n; k++)
				{
					//dp[i][j] : i回目で肥料jを使った時の最大の苗木の大きさ
					dp[i][j] = max(dp[i][j], dp[i-1][k]*T[k][j]);
				}
			}
		}

		long double res = -1; 
		for(int i = 0; i < n; i++)
		{
			res = max(res, dp[m-1][i]);
		}
	
		printf("%.2Lf\n",res);
	}
}

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>

double dp[100][100];

#define REP(i, n) for (int i = 0; i < (n); i++)
#define MAX(x, y) ((x) > (y) ? (x) : (y))

int main(void)
{
	double grow[100][100]; //[ツ前ツづ個氾ャツ猟ソ][ツ債。ツづ個氾ャツ猟ソ]
	int n, m;
	
	while (1){
		REP(i, 100) dp[0][i] = 1.0;
		
		scanf("%d%d", &n, &m);
		
		if (n == 0 || m == 0){
			break;
		}
		
		REP(i, n) REP(j, n) scanf("%lf", &grow[i][j]);
		
		for (int i = 1; i < m; i++){
			for (int j = 0; j < n; j++){
				dp[i][j] = dp[i - 1][0] * grow[0][j];
				for (int k = 1; k < n; k++){
					dp[i][j] = MAX(dp[i][j], dp[i - 1][k] * grow[k][j]);
				}
			}
		}
		
		double ans = 0;
		REP(i, n){
			ans = MAX(ans, dp[m - 1][i]);
		}
		
		printf("%lf\n", ans);
	}
	return (0);
}

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<n;i++){
		dp[0][i]=1;
	}
	for(int i=1;i<m;i++){
		for(int j=0;j<n;j++){
			double tmp=0;
			for(int k=0;k<n;k++){
				tmp=max(tmp,dp[i-1][k]*ef[k][j]);
			}
			dp[i][j]=tmp;
		}
	}
	for(int i=0;i<n;i++){
		ans=max(ans,dp[m-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;
	}
}

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

const int NMAX = 100;

int main() {
  int n, m;
  double dp[2][NMAX];
  double g[NMAX][NMAX];
  double lg[NMAX][NMAX];

  while (1) {
    cin >> n >> m;
    if (!n && !m) {
      break;
    }

    for (int i=0; i<n; ++i) {
      for (int j=0; j<n; ++j) {
        cin >> g[i][j];
        lg[i][j] = log(g[i][j]);
      }
    }
    for (int i=0; i<n; ++i) {
      dp[0][i] = 0.0;
    }

    for (int i=0; i<m-1; ++i) {
      for (int j=0; j<n; ++j) {
        dp[!(i&1)][j] = dp[i&1][j] + lg[j][0];
        for (int k=1; k<n; ++k) {
          dp[!(i&1)][j] = max(dp[!(i&1)][j], dp[i&1][k] + lg[k][j]);
        }
      }
    }

    double lans = -DBL_MAX;
    for (int i=0; i<n; ++i) {
      lans = max(lans, dp[!(m&1)][i]);
    }
    cout << fixed << setprecision(2) << round(exp(lans) * 100) / 100. << endl;
  }
  return 0;
}

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

using namespace std;

int n, m;
double grow[100][100];
double dp[100][3];//

int main() {
	while (cin >> n >> m, n * m) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cin >> grow[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++) {
				double M = 0;
				for (int k = 0; k < n; k++) {
					M = max(M, dp[i - 1][k] * grow[k][j]);
				}
				dp[i][j] = M;
			}
		}
		double ans = 0;
		for (int i = 0; i < n; i++) {
			ans = max(ans, dp[m - 1][i]);
		}
		int a = (ans + 0.005) * 100;
		ans = a;
		ans /= 100;
		cout << fixed << setprecision(2) << ans << endl;
		for (int i = 0; i < n; i++)for (int j = 0; j < n; j++)grow[i][j] = 0;
		for (int i = 0; i < m; i++)for (int j = 0; j < n; j++)dp[i][j] = 0;
	}
	return 0;
}