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<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];
			}
		}
		rep(i,n)dp[1][i] =1.00;

		double ans =0;
		for(int i =1;i <m;i++){
			for(int k =0;k <n;k++){//直前
				for(int j =0;j <n;j++){//直後
					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("%.2lf\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<pair<double,int>>> dp(m);

        FOR(i,0,n){
            FOR(j,0,n){
                cin >> bt[i][j] ;
            }
            dp[0].push_back(pair<double,int>(1.0,i));
        }

        double ans = 0.0;
        FOR(i,0,n-1){
            FOR(j,0,m){
                FOR(k,0,dp[i].size()){
                    double g;
                    int f;
                    g = dp[i][k].first;
                    f = dp[i][k].second;
                    dp[i+1].push_back(pair<double,int>(g*bt[f][j],j));
                    ans = max(ans, g*bt[f][j]);
                }
            }
        }
        printf("%.2f\n",ans);
    }
    return 0;
}

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

int main(){
  int n,m; 
  double data[101][101],tree[101][101];
  while ( cin >> n >> m ,n+m ) {
    for ( int i = 1; i <= n; i++ ) {
      for ( int j = 1; j <= n; j++ ) cin >> tree[i][j];
    }

    for ( int i = 1; i <= n; i++ ) {
      for ( int j = 1; j <= m; j++ ) data[i][j] = -1.0;
    }


    for ( int i = 1; i <= n; i++ ) data[i][1] = 1.0;
    
    int tmp;
    for( int i = 1; i <= n; i++ ) {
      tmp = i;
      for( int j = 1; j < m; j++ ) {
	int tmp2 = -1;
	double max = -1.0;
	for( int k = 1; k <= n; k++ ) {
	  //cout << "k" << " " << k << endl;
	  if( tree[tmp][k] > max ){
	    max = tree[tmp][k];
	    tmp2 = k;
	  }
	}
	data[i][j+1] = data[i][j] * tree[tmp][tmp2];
	//	cout << "tmp" << " " << tmp << " " << "tmp2" << " " << tmp2 << endl;
	tmp = tmp2;
      }
    }

    /* for ( int i = 1; i <=n; i++ ) {
      for( int j = 1; j <= n; j++ ) printf("%.2f ",data[i][j]);
      cout << endl;
      }*/
    double maxv = -1.0;
    for( int i = 1; i <= n; i++ ) maxv = max( data[i][n], maxv );

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

  }
  return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<vector>
#include<functional>

using namespace std;

#ifdef DEBUG
#define dprintf      printf
#define dout(x)      cout<<#x" = "<<(x)<<endl
#define darray(x,n)    {int i;rep(i,n)cout<<#x"["<<i<<"] = "<<*((x)+i)<<endl;}
#define dloop(i,s,g) for((i)=(s);(i)<(g);(i)++)
#define drep(i,n)    for((i)=0;(i)<(n);(i)++)
#define dstop()      scanf("%*c")
#else
#define dprintf      (1)?0:printf
#define dout(x)
#define darray(x,n)
#define dloop(i,s,g) if(1){}else
#define drep(i,n)    if(1){}else
#define dstop()      if(1){}else
#endif

#define F    first
#define S    second
#define pb   push_back
#define mp   make_pair

#define loop(i,s,g) for((i)=(s);(i)<(g);(i)++)
#define rep(i,n)    for((i)=0;(i)<(n);(i)++)
#define all(x)      (x.begin(),x.end())
#define in(T,...) T __VA_ARGS__; impl(__VA_ARGS__);
#define array(T,id,n) T id[n]; rep(i,n)cin>>id[i];

//#define int long long;
#ifndef int
#define INF  (0x7fffffff)
#else
#define INF (0x7fffffffffffffff)
#endif

typedef  long long           ll;
typedef  unsigned            ui;
typedef  unsigned long long  ull;
typedef  pair<int,int>       i_i;
typedef  pair<ll,int>        ll_i;
typedef  pair<ll,ll>         ll_ll;
typedef  pair<double,int>    d_i;
typedef  pair<double,double> d_d;

void impl(){};
template <typename T,typename... TS >
void impl(T &head,TS &... tail)
{
  cin>>head;
  impl(tail ...);
}

signed main(void)
{
  while(1)
    {
      int i,j,k;
      int n,m;
      double g[112][112]={};
      double dp[112][112]={};
      cin>>n>>m;
      if(!n)break;
      rep(i,n)
	rep(j,n)
	  cin>>g[i][j];
      rep(i,n)
	dp[i][0]=1;
      for(j=1;j<m;j++)
	rep(i,n)
	  {
	    double max=0.0;
	    rep(k,n)
	      max=dp[k][j-1]*g[k][i]>max?dp[k][j-1]*g[k][i]:max;
	    dp[i][j]=max;
	  }
      double max=0.0;
      rep(i,n)
	max=dp[i][n-1]>max?dp[i][n-1]:max;
      printf("%.2f\n",max);
    }
  return 0;
}