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 <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <queue>
#include <string>
#include <complex>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define repa(i,s,e) for(int i=s; i<=e; i++)
#define repd(i,s,e) for(int i=s; i>=e; i--)

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int MAX_N = 101;
const int MAX_M = 101;
int N, M;
double table[MAX_N][MAX_N];
double dp[MAX_M][MAX_N]; 

void solve() {
	repa(i,0,M) rep(j,N) dp[i][j] = 0.0;

	rep(i,N) dp[0][i] = 1.0;
	repa(i,1,M-1) {
		rep(j,N) {
			double maxval = 0.0;
			rep(k,N) {
				double s = dp[i-1][k] * table[k][j];
				maxval = max(s, maxval);
			}
			dp[i][j] = maxval;
		}
	}

	double maxval = 0.0;
	rep(i,N) {
		maxval = max(maxval, dp[M-1][i]);
	}
	printf("%.6f\n", maxval);
}

int main() {
	while(scanf("%d%d",&N,&M), N|M) {
		rep(i,N) {
			rep(j,N) {
				scanf("%lf", &table[i][j]);
			}
		}
		solve();
	}
}

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,0.0));
    for(i=0;i<n;i++)for(j=0;j<n;j++)cin>>manure[i][j];
    for(j=0;j<n;j++)dp[0][j]=1.0;
    for(i=1;i<n;i++){
      for(j=0;j<n;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>

using namespace std;

int n, m;
double in[100][100], dp[101][101];

int main( void )
{
	while(cin >> n >> m, n | m) {

		for(int i=0; i < n; ++i)
			for(int j=0; j < n; ++j) {
				cin >> in[i][j];
				dp[i+1][j] = 0;
			}
		fill(dp[0], dp[0]+n, 1);

		for(int i=1; i < m; ++i)
		{
			for(int j=0; j < n; ++j)
			{
				for(int k=0; k < n; ++k)
				{
					//printf("(%lf, %lf, %lf) = (%lf, %lf)\n", i, j, k, dp[i][j], in[j][k]*dp[i-1][j]);
					dp[i][k] = max(dp[i][k], in[j][k] * dp[i-1][j]);
					//dp[i][j] = max(dp[i][j], in[k][j] * dp[i-1][j]);
				}
			}
		}
		double Max = -1.0;
		for(int i=0; i < n; ++i) {
			Max = max(Max, dp[m-1][i]);
		}
		//for(int i=0; i < m; ++i,printf("\n"))
		//	for(int j=0; j < n; ++j) printf("%.2lf ", dp[i][j]);
		
		printf("%.2lf\n", Max);
	}
	return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define dump(o) { cerr << #o << " " << o << endl; }
#define dumpc(o) { cerr << #o; for (auto &e : (o)) cerr << " " << e; cerr << endl; }
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

#define MAX_M 101
#define MAX_N 100

signed main() {
	double a[MAX_N][MAX_N];
	double dp[MAX_M][MAX_N];
	for (int n, m; cin >> n >> m&&n;) {
		memset(dp, 0, sizeof(dp));
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cin >> a[i][j];
			}
		}

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

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cassert>
#include<cmath>
#define EPS 1e-10
using namespace std;
typedef pair<double,int> P;
int m,n;
double total;
double dp[110][110];
int Just;
bool al;
vector<P> stren;
vector<double> matrix[110];
void rec(int next,int counter,double sam){
  if(counter >= m){
    al = true;
    dp[Just][m] = max(dp[Just][m],sam);
    return;
  }
  int Maax = stren[next].first;
  for(int i=0;i<n;i++){   
    if(fabs(Maax-matrix[next][i]) < EPS)rec(i,counter+1,sam*matrix[next][i]);
  }  
}


int main(){
  
  double In;
 
  while(cin >> n >> m && n && m){
    for(int i=0;i<=n;i++)matrix[i].clear();
    stren.clear();
    for(int i=109;i>=0;i--)for(int j=0;j<110;j++)dp[j][i] = 0;
    double MaX[n+1];
    int Pos[n+1];
    for(int i=0;i<n;i++)MaX[i] = 0;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	cin >> In;
	matrix[i].push_back(In);
	if(MaX[i] < In+EPS){
	  MaX[i] = In;
	  Pos[i] = j;
	}
      }
    }
  
    for(int i=0;i<n;i++){
      stren.push_back(P(MaX[i],Pos[i]));
    }

    double ans = -1;
 
      for(int I=0;I<n;I++){
	Just = I;
	rec(I,1,1.0);
	ans = max(ans,dp[Just][m]);
      }
    
    printf("%.2f\n",ans);

  }
  return 0;
}

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

double tbl[100][100]; // iの後にjを与えたときの成長度

int main() {
    int n, m;
    while (cin >> n >> m, (n || m)) {
        for (int i=0; i<n; ++i) {
            for (int j=0; j<n; ++j) {
                cin >> tbl[i][j];
            }
        }
        double dp[101][100] = {}; // i回目にjを与えたときの最大サイズ
        for (int i=0; i<100; ++i) {
            dp[1][i] = 1.0;
        }
        for (int t=2; t<=m; ++t) {
            for (int i=0; i<n; ++i) {
                for (int j=0; j<n; ++j) {
                    dp[t][i] = max(dp[t][i], dp[t-1][j] * tbl[j][i]);
                }
            }
        }
        double res = -1e8;
        for (int i=0; i<n; ++i) {
            res = max(res, dp[m][i]);
        }
        cout.precision(2);
        cout << fixed << res << endl;
    }
    return 0;
}