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<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
#define INF (1 << 30)
using namespace std;

double dp[105][105];
double g[105][105];

double solve(int n, int m){
    rep(i,n) dp[0][i] = 1;
    range(day,1,m){
        rep(now,n){
            rep(before,n){
                dp[day][now] = max(dp[day][now], dp[day - 1][before] * g[before][now]);
            }
        }
    }

    double retval = 0;
    rep(i,n){
        retval = max(dp[m - 1][i], retval);
    }

    return retval;
}

int main(){
    int n, m;
    while(cin >> n >> m, n||m){
        rep(i,105) rep(j,105) dp[i][j] = 0;
        rep(i,n) rep(j,n) cin >> g[i][j];
        printf("%.2lf\n", solve(n, m));
    }
}

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

# define MAX_N 100
# define MAX_M 100

int n, m;
double dp[MAX_N][MAX_M];

double board[MAX_M][MAX_M];

int main() {
	while (1) {
		std::cin >> n >> m;
		if (n == 0 && m == 0)
			break;
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < m; ++j)
				dp[i][j] = 0;
		for (int i = 0; i < m; ++i) {
			for (int j = 0; j < m; ++j)
				std::cin >> board[i][j];
		}
		std::fill(dp[0], dp[0] + m, 1);
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < m; ++j) {
				for (int k = 0; k < m; ++k) {
					dp[i][j] = std::max(dp[i][j], dp[i - 1][k] * board[k][j]);
				}
			}
		}
		double res = 0;
		for (int i = 0; i < m; ++i)
			res = std::max(res, dp[n - 1][i]);
		std::cout << std::fixed << std::setprecision(2) << res << std::endl;
	}
	return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <climits>
using namespace std;

typedef vector <double> VD;
typedef vector <VD> VVD;
typedef vector <int> VI;

class info
{
public:
	int		id;
	double	score;
};

VVD C;	// cost
vector <info> prev;
vector <info> next;
int n;	// ì¿ÌíÞ
int m;	// ì¿ð^¦éñ
double answer;

void solve()
{
	prev = vector <info>( n );
	next = vector <info>( n );

	for ( int i = 0; i < n; i++ )
	{
		prev[i].id = i;
		prev[i].score = 1.0;
	}

	for ( int k = 1; k < m; k++ )
	{
		for ( int i = 0; i < n; i++ )
		{
			next[i].score = INT_MIN;
			for ( int j = 0; j < n; j++ )
			{
				double tmp = prev[j].score * C[prev[j].id][i];
				if ( next[i].score < tmp )
				{
					next[i].score = tmp;
					next[i].id = j;
				}
			}
		}
		prev = next;
	}

	answer = prev[0].score;
	for ( int i = 1; i < n; i++ )
		answer = max( answer, prev[i].score );
}

int main( void )
{
	while ( cin >> n >> m && n > 0 && m > 0 )
	{
		C = VVD( n, VD( n ) );

		// üÍ
		for ( int i = 0; i < n; i++ )
		{
			for ( int j = 0; j < n; j++ )
			{
				cin >> C[i][j];
			}
		}

		solve();

		cout.setf( ios::fixed );
		cout.precision( 2 );
		cout << answer << endl;
	}

	return 0;
}

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

int main() {
	int n, m;
	while(cin >> n >> m, n || m) {
		double gr[128][128] = {0};
		double dptab[128][128] = {0};
		for(int i = 0; i < 128; i++) {
			dptab[0][i] = 1.0;
		}
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				cin >> gr[i][j];
			}
		}

		for(int i = 1; i < m; i++) {
			for(int j = 0; j < n; j++) {
				for(int k = 0; k < n; k++) {
					dptab[i][j] = max(dptab[i][j], dptab[i - 1][j] * gr[k][j]);
				}
			}
		}

		double ans = -1;
		for(int i = 0; i < n; i++) {
			ans = max(dptab[m-1][i], ans);
		}

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

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

double fig[100][100];
int n,m;

double serch(int kind,double point,int count){
	if(count==m)
		return point;
	double ans = 0.0;
	int num;
	for(int i=0;i<n;i++){
			if(ans < fig[kind][i]){
				ans = fig[kind][i];
				num = i;
			}
	}
	return serch(num,point*ans,count+1);
}
int main()
{
	while(cin >> n >> m){
		if(!n && !m)
			break;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cin >> fig[i][j];
			}
		}
		double ans = 0.0;
		for(int i=0;i<n;i++){
			ans = max(ans,serch(i,1.0,1));
		}
		if(static_cast<int>(ans*1000)-(static_cast<int>(ans)*1000) >= 5)
			ans+= 0.01;
		cout << setprecision(2)<< fixed << ans << endl;
	}
	return 0;
}

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

int main()
{
  for(;;){
    int n,m;
    cin >> n >> m;
    if(n==0){return 0;}
    double map[n][n];
 
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	cin >> map[i][j];
      }
    }
  
    double dp[m][n];

   
  
    for(int i=0;i<m;i++){for(int j=0;j<n;j++){dp[i][j]=-1.0;}}
    for(int i=0;i<n;i++){dp[0][i]=1.0;}
  
    for(int i=0;i<m;i++){
      for(int j=0;j<n;j++){
	for(int k=0;k<n;k++){\
	  dp[i+1][k]=max(dp[i+1][k],dp[i][j]*map[j][i]);
	}
      }
    }
  
    for(int i=0;i<m;i++){
      for(int j=0;j<n;j++){
	//cout << dp[i][j] << " ";
      }
      //cout << endl;
    }

    double max1=-1.0;
    for(int i=0;i<n;i++){
      max1=max(max1,dp[m-1][i]);
    }
    //printf("%f",max1);
    printf("%2f\n",max1);
  }
}

C++: #include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define Rep(i,n) for(int i = 1 ; i < n ; i++)
#define MAX 101

int main(){
  double dp[MAX][MAX],nae[MAX][MAX];
  int n,m;
  
  while(cin >> n >> m, n+m){
    fill(dp[0],dp[MAX-1],0);
    rep(i,n) rep(j,n) cin >> nae[i][j]; 
   
    rep(i,n) dp[0][i] = 1.0;
    Rep(i,m) rep(j,n){ dp[i][j] = -1; rep(k,n)
      dp[i][j] = max(dp[i][j],dp[i-1][k]*nae[k][j]);
    }
    double ans = -1;
    rep(j,n)
      ans = max(ans,dp[m-1][j]);

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

  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

const double inf = 1e20;

int main() {
  for(int n, m; cin >> n >> m && (n|m);) {
    vector<vector<double> > g(n, vector<double>(n));
    for(int i = 0; i < n; ++i) {
      for(int j = 0; j < n; ++j) {
        cin >> g[i][j];
      }
    }
    vector<double> h(n, 1.0);
    for(int t = 0; t < m-1; ++t) {
      vector<double> nh(n, -inf);
      for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
          nh[j] = max(nh[j], h[i] * g[i][j]);
        }
      }
      h = nh;
    }
    printf("%.2f\n", *max_element(h.begin(), h.end()));
  }
  return 0;
}