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 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];
	REP(i,2)REP(j,101) dp[i][j] = 0;
	REP(i,101) dp[0][i] = 1;
	REP(i,m-1){
	    REP(j,101) dp[1][i] = 0;
	    REP(j,n){
		dp[1][j] = dp[0][j] * d[0][j];
		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 * 1000;
	t = t % 10;
	if(t >= 5) ans += 0.01;
	printf("%.2f\n",ans);
    }
    return 0;
}

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

using namespace std;

struct Data {
	int idx;
	double point;
};

int n, m;
//double map[100][100], Max;
Data data[100];
double Max;

void search( int prev, double point, int count )
{
	if(count == m) {
		if(Max < point) {
			Max = point;
		}
		return;
	}
	search(data[prev].idx, point*data[prev].point, count + 1);
}

int main( void )
{
	while(cin >> n >> m, n | m) {
		Max = 0;
		for(int i=0; i < 100; ++i) data[i].point = 0;
		for(int i=0; i < n; ++i)
			for(int j=0; j < n; ++j) {
				double point;
				cin >> point;
				if(point > data[i].point) {
					data[i].idx = i;
					data[i].point = point;
				}
			}
		for(int i=0; i < n; ++i)
			search(i, 1.0, 1);
		printf("%.2f\n", Max);
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
	int n,m;
	double g[100][100];
	double dp[100][100];

	while(cin >> n >> m)
	{
		if(n == 0 && m == 0) break;
	
		memset(g,0,sizeof(g));
		memset(dp,0,sizeof(dp));
		
		rep(i,n)
		{
			rep(j,n)
			{
				cin >> g[i][j];
			}
		}

		rep(i,m) rep(j,n) dp[i][j] = 0;

		rep(i,n) dp[0][i] = 1;

		REP(i,1,m)
		{
			rep(j,n)
			{
				rep(k,n)
				{
					dp[i][j] = max(dp[i][j],dp[i-1][k]*g[k][j]);
				}
			}
		}

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

		cout << fixed;
		cout.precision(2);
		cout << ans << endl;

	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<stdio.h>
using namespace std;
int n,m;
double t[101][101],ans;
double dp[101][101];
int main(){
  while(cin>>n>>m&&n){
    for(int i=1;i<=n;i++){
      for(int j=1;j<=n;j++){
	cin>>t[i][j];
      }
    }
    for(int i=0;i<=100;i++)dp[0][i]=dp[1][i]=1.0;

    for(int i=2;i<=m;i++){
      for(int j=1;j<=n;j++){
	dp[i][j]=0.0;
	for(int k=1;k<=n;k++){
	  dp[i][j]=max(dp[i][j],dp[i-1][k]*t[k][j]);
	}
      }
    }

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

        FOR(i,0,n)
            ans = max(ans,dp[m-1][i]);

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

C++: #include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
using namespace std;

#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)

double dt[102][102];
double dp[102][102];
int n;

double dfs(int d,int v){
	if(abs(dp[d][v]+1)>1e-6)return dp[d][v];
	if(d == 0) return 1.0;
	double r=-1;
	for(int i = 0 ; i < n ; i++){
		r = max(r,dfs(d-1,i) * dt[i][v]);
	}

	return dp[d][v] = r;
}

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

		rep(i,n)
			rep(j,n)cin>>dt[i][j];
		rep(i,102)rep(j,102)dp[i][j] = -1;
		
		//rep(i,n)rep(j,n)cout<<dt[i][j]<<(j==n-1?'\n':' ');


		double r = 0;
		rep(i,n){
			r = max(r,dfs(m-1,i));
		}
		printf("%.2f\n",r+0.005);
	}
}

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

const int LIMIT = 101;

int main()
{
	int n, m;
	double g[ LIMIT ][ LIMIT ];
	double dp[ LIMIT ][ LIMIT ];

	while( cin >> n >> m && ( n || m ) ){
		memset( g, 0, sizeof(g) );
		memset( dp, 0, sizeof(dp) );
		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[ 1 ][ i ] = 1.0;
		}
		for( int i = 2; 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 ] * g[ k ][ j ] );
				}
			}
		}
		double result = 0.0;
		for( int i = 0; i < n; ++i ){
			result = max( result, dp[ m ][ i ] );
		}
		cout << fixed << setprecision( 2 ) << result << endl;
	}

	return 0;
}

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

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

VVD C;
int n; // ì¿ÌíÞ
int m; // ì¿ð^¦éñ
double answer;
double tmp;

/* æÃ~ÉT[` */
void greedy_search( int prev, int depth )
{
	if ( m == depth )
	{
		answer = max( answer, tmp );
		return;
	}

	double max_value = 0.0;
	for ( int i = 0; i < n; i++ )
	{
		max_value = max( max_value, C[prev][i] );
	}

	double backup = tmp;
	for ( int i = 0; i < n; i++ )
	{
		if ( C[prev][i] == max_value )
		{
			tmp = backup;
			tmp *= C[prev][i];
			greedy_search( i, depth + 1 );
		}
	}

}

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

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

		// Tõ
		answer = 0.0;
		for ( int i = 0; i < n; i++ )
		{
			tmp = 1.0;
			greedy_search( i, 1 );
		}
		cout.setf( ios::fixed );
		cout.precision( 2 );
		cout << answer << endl;
	}

	return 0;
}