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 <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    while(true){
	int m,n;
	cin >> n >> m;
	vector< vector<double> > d(n,vector<double>(n,0.0) );
	if(n == 0 && m == 0) break;
	REP(i,n)REP(j,n) cin >> d[i][j];
	double ans = 0.0;
	vector<double> a(n);
	double dp[2][101];
	memset(dp,1,sizeof(dp));
	REP(i,101) dp[0][i] = 1;
	REP(i,m-1){
	    REP(j,101) dp[1][i] = 0;
	    REP(j,n){
		REP(k,n){
		    dp[1][j] = max(dp[1][j],dp[0][j] * d[k][j]);
		}
	    }
	    swap(dp[0],dp[1]);
	}
	REP(i,n) ans = max(dp[0][i],ans);
	int t = ans * 100;
	t = t % 10;
	if(t >= 5) ans = (100 * ans - t)/100;
	else (100 * ans - t + 1)/100;
	printf("%.2f\n",ans);
    }
    return 0;
}

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

int main(void){
	double dp[100][100];	// [回数][種類]
	double table[100][100];
	int N, T;

	while(true){
		cin >> T >> N;
		if( T == 0 && N == 0)
			break;
		for(int bef=0; bef<T; bef++)
			for(int cur=0; cur<T; cur++)
				cin >> table[bef][cur];

		// init
		for(int n=0; n<N; n++)
			for(int t=0; t<T; t++)
				dp[n][t] = n == 0 ? 1 : 0;
		
		// calc
		for(int n=0; n<N-1; n++){
			for(int tcur=0; tcur<T; tcur++){
				for(int taft=0; taft<T; taft++){
					dp[n+1][taft] = max(dp[n+1][taft], dp[n][tcur]*table[tcur][taft]);
				}
			}
		}

		double res = 0;
		for(int t=0; t<T; t++)
			res = max(dp[N-1][t], res);

		res = res * pow((double)10, 2);
		res = (double)(int)(res + 0.5);
		res = res * pow((double)10, -2);


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

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

int main() {
  double f[101][101];
  double dp[101][101];
  int n,m;
  while (cin >> n >> m,n||m) {
    
    for ( int i = 0; i < n; i++ ) {
      for ( int j = 0; j < n; j++ ) {
	cin >> f[i][j];
      }
    }

    for ( int i = 0; i < m; i++ ) {
      for ( int j = 0; j < n; j++ ) {
	dp[i][j] = 0.0;
      }
    }

    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][j] * f[j][k] );
	}
      }
    }
    double ans = 0.0;
    for ( int i = 0; i < n; i++ ) {
      ans = dp[m-1][i];
    }
      
    printf ("%.2f\n", ans );
  }
  return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

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

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define rep(i,x) for(int i=0;i<(x);++i)
#define rep1(i,x) for(int i=1;i<=(x);++i)
#define rrep(i,x) for(int i=(x)-1;i>=0;--i)
#define rrep1(i,x) for(int i=(x);i>=1;--i)
#define FOR(i,a,x) for(int i=(a);i<(x);++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T get(){T a;cin>>a;return a;}
template<typename T>T rev(T a){reverse(all(a));return a;}
template<typename T>istream&operator>>(istream&is,vector<T>&vec){rep(i,vec.size())is>>vec[i];return is;}
template<typename T>vector<T>&sort(vector<T>&a){sort(all(a));return a;}

const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;

double table[100][100];

double dp[100][100][100]; // dp[times][cur][prev]

signed main()
{
    int N, M; cin >> N >> M;

    rep(i, N) rep(j, N) cin >> table[i][j];

    rep(i, N) rep(j, N) dp[0][i][j] = 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][k] = max(dp[i][j][k], *max_element(dp[i - 1][k], dp[i - 1][k] + N) * table[k][j]);
            }
        }
    }

    double ans = 0;

    rep(i, 100) rep(j, 100) ans = max(ans, dp[M - 1][i][j]);

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

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
using namespace std;
double dp[100][100],g[100][100];
int main(){
  int n, m;
  while(cin >> n >> m , n){
    for(int i = 0 ; i < n ; i ++ ){
      for(int j = 0 ; j < n ; j++ ){
        cin >> g[i][j];
      }
    }
    fill_n( dp[0], n, 1.0);
    fill_n( dp[1], 9900, 0);
    for(int i = 1 ; i < m ; i++ ){ //回数
      for(int prev = 0 ; prev < n ; prev++ ){ // prev
        for(int now = 0 ; now < n ; now++ ){ // now
          dp[i][now] = max( dp[i][now], dp[i - 1][prev] * g[prev][now]);
        }
      }
    }
    cout << fixed << setprecision(2) << *max_element( dp[m - 1], dp[m - 1] + n ) << endl;
  }
}

C++: #include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

double table[100][100];


int main(){
	int n, m ;
	while(cin >> n >> m , n){
		rep(i,n)rep(j,n)cin >> table[i][j];
		
		double dp[100][100] = {{0.0}};
		
		rep(i,n)dp[0][i] = 1.0;
		
		rep(i,m-1){
			rep(j,n){
				rep(k,n){
					dp[i+1][j] = max(dp[i+1][j] , dp[i][j] * table[k][j]);
				}
			}
		}
		double ret = 0;
		rep(i,n){
			ret = max(ret,dp[m-1][i]);
		}
		long long out = (ret * 100.0);
		printf("%.2lf\n",out/100.0);
	}
	
}