Go: // n×nの成長度表に現れる数字を重複を許してm-1個選んで掛け合わせる時の最大値を求める
// ->掛け算型のDP

package main

import (
	"bufio"
	"os"
	"strings"
	"strconv"
	"log"
	"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<iostream>
#include <iomanip>

using namespace std;
const int INF = 1000000;

double data[100][100];
double dp[100][100];
int n,m;

double check(int i,int j,int mm)
{
  if(i==-1)
    {
      double tmp=check(j,0,mm-1);
      for(int xx=1;xx<n;xx++)
	{
	  tmp=max(tmp,check(j,xx,mm-1));
	}
      return tmp;
    }
  else
    {
      if(mm<0)
	return -INF;
      else if(mm==0)
	return data[i][j];
      else if(dp[i][j]!=-1)
	return dp[i][j];
      else
	{
	  double tmp=check(j,0,mm-1)*data[i][j];
	  for(int xx=1;xx<n;xx++)
	    {
	      tmp=max(tmp,check(j,xx,mm-1)*data[i][j]);
	    }
	  dp[i][j]=tmp;
	  return tmp;
	}
    }
}

int main()
{

  for(;cin>>n>>m,n;)
    {
      for(int i=0;i<100;i++)
	for(int j=0;j<100;j++)
	  {
	    dp[i][j]=-1.0;
	  }
      for(int i=0;i<m;i++)
	for(int j=0;j<m;j++)
	  {
	    double tmp;
	    cin>>tmp;
	    data[i][j]=tmp;
	  }
      double ans=check(-1,0,m-1);
      for(int i=1;i<n;i++)
	{
	  ans=max(ans,check(-1,i,m-1));
	}
      cout<< fixed<<setprecision(2)<< ans << endl;
      
    }
}

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

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define EACH( v, c ) for ( auto &v : c )

#define ITER( c ) __typeof( (c).begin() )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

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

int main()
{
	cin.tie( 0 );
	ios::sync_with_stdio( false );

	cout.precision( 10 );
	cout << fixed;

	while ( true )
	{
		int n, m;
		cin >> n >> m;

		if ( !( n | m ) )
		{
			break;
		}

		VVD table( n, VD( n, 0. ) );

		REP( i, 0, n )
		{
			REP( j, 0, n )
			{
				cin >> table[i][j];
			}
		}

		VVD dp( m, VD( n, 0. ) );
		fill( ALL( dp[0] ), 1. );

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

		cout << *max_element( ALL( dp[ m - 1 ] ) ) << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <sstream>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <stack>
#include <list>
using namespace std;
#define INF 100000000
typedef long long int lli;
typedef pair<int,int> P;

double g[101][101];
double dp[101][101];

int main(){
	int n,m;
	while(cin>>n>>m){
		if(n==0&&m==0)  break;
		for(int i=0; i<=m; ++i){
			for(int j=0; j<n; ++j){
				dp[i][j]=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[1][i]=1;
		}
		for(int i=2; i<=m; ++i){
			for(int j=0; j<n; ++j){
				double tmp=dp[i][j];
				for(int k=0; k<n; ++k){
					tmp=max(tmp,dp[i-1][k]*g[k][j]);
				}
				dp[i][j]=tmp;
			}
		}
		double ans=0;
		for(int i=0; i<n; ++i){
			ans=max(ans,dp[m][i]);
		}
		ans=((int)(ans*100+0.5))/100;
		printf("%.2f\n",ans);
	}
	return 0;
}

C++: #include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,b,n) for(int i=b;i<n;i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int n,m;
const int MAX_N =120;
const int MAX_M =120;
double dp[MAX_N][MAX_M];//dp[i][j]:=直前にjを与え、i回目に肥料を与えたときの最大の成長
double memo[MAX_N][MAX_N];
int main(){
	while(1){
		cin>>n>>m;
		if(n==0&&m==0){
			break;
		}
		for(int i =0;i <MAX_N;i++){
			for(int j =0;j <MAX_N;j++){
				dp[i][j] =0;
				memo[i][j]=0;
			}
		}
		rep(i,n){
			rep(j,n){
				cin>>memo[i][j];
			}
		}
		bool flag =false;
		if(m==1){
			printf("%.2f\n",1.00);
			continue;
		}

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

		double ans =0;
		for(int i =1;i <m;i++){
			for(int j =0;j <n;j++){//直後
				for(int k =0;k <n;k++){//直前
					dp[i+1][j] =max(dp[i+1][j],dp[i][k]*memo[k][j]);
				}
			}
		}
		rep(i,n)ans=max(ans,dp[m][i]);
		ans +=0.005;
		ans =ans*100;
		ans =(int)ans;
		ans =(double)ans/100;
		printf("%.2f\n",m==1?1:ans);
	}
	return 0;
}