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 <cstdio>
#include <algorithm>
#include <vector>
#include <sstream>
#include <cmath>
#include <queue>

using namespace std;

double g[10][100][100];
double ans[100][100];
double ans_dummy[100][100];

int n, m;

void multi(double a[100][100], double b[100][100], double c[100][100]){
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			double max = 0;
			for(int k = 0; k < n; k++){
				if(a[i][k] * b[k][j] > max){
					max = a[i][k] * b[k][j];
				}
			}
			c[i][j] = max;
		}
	}
}

int main(){
	
	while(true){
		
		cin >> n >> m;
		
		if(n == 0 && m == 0){
			break;
		}
		
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				cin >> g[0][i][j];
				ans[i][j] = 1;
			}
		}
		
		m--;
		
		for(int i = 0; i < 9; i++){
			multi(g[i], g[i], g[i + 1]);
			if(m % 2 == 1){
				multi(ans, g[i], ans_dummy);
				for(int j = 0; j < n; j++){
					for(int k = 0; k < n; k++){
						ans[j][k] = ans_dummy[j][k];
						//cout << ans[j][k] << " ";
					}
					//cout << endl;
				}
			}
			m /= 2;
		}
		
		double max = 0;
		
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				if(max < ans[i][j]){
					max = ans[i][j];
				}
			}
		}
		
		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 = 0;
        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<iostream>
#include<algorithm>
#include<vector>
#include<iomanip>
using namespace std;
int main()
{
  cout<<setprecision(2);
  cout<<setiosflags(ios::fixed);
  int n,m,i,j,k;
  long double M;
  while(cin>>n>>m,n|m){
    vector< vector<long double> >manure(n,vector<long double>(n)),dp(n,vector<long double>(n,1.0));
    for(i=0;i<n;i++)for(j=0;j<n;j++)cin>>manure[i][j];
    for(i=1;i<n;i++){
      for(j=0;j<n;j++){
	dp[i][j]=dp[i-1][j];
	for(k=0;k<n;k++){
	  dp[i][j]=max(dp[i][j],dp[i-1][k]*manure[k][j]);
	}
      }
    }
    M=0.0;
    for(j=0;j<n;j++)M=max(M,dp[n-1][j]);
    cout<<M<<endl;
  }
}

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

using namespace std;
int n, m;
double cal(double g[][101]) {
  int i, j, k;
  double dp[110][110] = {};
  // double MAX = 0.0;
  double all_MAX = 0.0;
  
  for(i = 1; i <= n; i++) {
    dp[1][i] = 1.0;
  }
  
  for(i = 2; i <= m; i++)
    for(j = 1; j <= n; j++) {
      dp[i][j] = 0.0;
      for(k = 1; k <= n; k++) {
	dp[i][j] = max(dp[i-1][k]*g[k][j], dp[i][j]);
      }
    }
  
  for(i = 1; i <= m; i++) {
    for(j = 1; j <= n; j++){
      // cout << dp[i][j] << ' ';
      all_MAX = max(dp[i][j], all_MAX);
    }
    // cout << endl;
  }
  
  return all_MAX;
}

	  
int main() {
  int i, j;
  while(cin >> n >> m, n != 0 || m != 0) {
    double g[101][101] = {};
    
    for(i = 1; i <= n; i++)
      for(j = 1; j <= n; j++)
	cin >> g[i][j];
    printf("%.2f\n", cal(g));
  }
  
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

int main() {
    int n, m;
    while(cin >> n >> m, n){
        auto dp = make_v(m, n, 0.0);
        auto G = make_v(n, n, 0.0);
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                cin >> G[i][j];
            }
        }
        for (int i = 0; i < n; ++i) {
            dp[0][i] = 1.0;
        }
        for (int i = 0; i < m-1; ++i) {
            for (int j = 0; j < n; ++j) {
                for (int k = 0; k < n; ++k) {
                    chmax(dp[i+1][k],dp[i][j]*G[j][k]);
                }
            }
        }
        printf("%.2lf\n", *max_element(dp.back().begin(),dp.back().end()));
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
using namespace std;
double key[100][100];
double table[100][100][100];

void Init(int n, int m){
	for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) for(int k = 0; k < m+1; k++)table[i][j][k] = 0;
}

double memo(int prev, int cur, int count, int limit, int kind){
	if(table[prev][cur][count]) return table[prev][cur][count];
	if(count==limit) return 1.0;
	double Max = 0;
	for(int i = 0; i < kind; i++){
		Max = max(Max, memo(i, prev, count+1, limit, kind));
	}
	table[prev][cur][count] = Max*key[prev][cur];
	return table[prev][cur][count];
}

int main(){
	int n, m;
	while(cin >> n >> m && ((n!=0)||(m!=0))){
		Init(n, m);
		for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) cin >> key[i][j];
		for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) table[i][j][0] = memo(i, j, 1, m, n);
		double max = 0;
		for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(max < table[i][j][0]) max = table[i][j][0];
		printf("%0.2f\n", max);
	}

	return 0;
}