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<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;
      double g[112][112]={};
      double dp[112][112]={};
      in(int,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,m)
	max=dp[i][m-1]>max?dp[i][m-1]:max;
      printf("%.2f\n",max);
    }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
using namespace std;
double key[100][100];
double table[100][100];

void Init(int n, int m){
	for(int i = 0; i < n; i++) for(int j = 0; j < m+1; j++) table[i][j] = 0;
}

double memo(int cur, int count, int limit, int kind){
	if(table[cur][count]) return table[cur][count];
	if(count==limit) return 1.0;
	double Max = 0;
	int prev = 0;
	for(int i = 0; i < kind; i++){
		double tmp = memo(i, count+1, limit, kind);
		if(Max <= tmp){
			if(Max*key[prev][cur] < tmp*key[i][cur]){
				Max = tmp;
				prev = i;
			}
		}
	}
	table[cur][count] = Max*key[prev][cur];
	return table[cur][count];
}

int main(){
	int n, m;
	while(cin >> n >> m && ((n!=0)||(m!=0))){
		Init(n, m);
		for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) cin >> key[i][j];
		for(int i = 0; i < n; i++) table[i][0] = memo(i, 1, m, n);
		double max = 0;
		for(int i = 0; i < n; i++) if(max < table[i][0]) max = table[i][0];
		printf("%0.2f\n", max);
	}

	return 0;
}

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

double growth[200][200];
double dp[200][200];

int main()
{
	int n, m;
	
	while (scanf("%d %d", &n, &m), n + m){
		for (int i = 0; i < 200; i++){
			dp[i][0] = 1.0;
			for (int j = 1; j < 200; j++){
				dp[i][j] = 0.0;
			}
		}
		
		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				scanf("%lf", &growth[i][j]);
			}
		}
		
		for (int i = 0; i < m - 1; i++){
//			printf("%d\n", 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][j] * growth[k][j]);
				}
//				printf("%d %lf\n", j, dp[i + 1][j]);
			}
		}
		
		double maxi = 0.0;
		for (int i = 0; i < n; i++){
			maxi = max(maxi, dp[m - 1][i]);
		}
		
		printf("%lf\n", maxi);
	}
	
	return 0;
}

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

const int MAX_N = 100, MAX_M = 100;
const double EPS = 1e-10;

int n,m;
long double g[MAX_N][MAX_N], dp[2][MAX_N];

int main()
{
    int m, n;
    while(cin >> n >> m && n) {
        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[0][i] = 1.0;
            dp[1][i] = -1.0;
        }
        
        for(int i = 0; i < m - 1; i++) {
            for(int j = 0; j < n; j++) {
                for(int k = 0; k < n; k++) {
                    dp[(i+1) % 2][k] = max(dp[(i+1) % 2][k], dp[i % 2][j] * g[j][k]);
                }
            }
        }
        long double ret = 0.0;
        for(int i = 0; i < n; i++) 
            ret = max(ret, dp[(m-1) % 2][i]);
        printf("%.2Lf\n", ret);

    }
    
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
using namespace std;
#define rep(i, j) for(int i = 0; i < j; i++)
#define f(i, k, j) for(int i = k; i < j; i++)
#define P pair<int, int>
const int INF = (1 << 26);

int n, m;
vector< vector<double> > vec, dp;

void solve(){
    f(j, 2, m + 1){
        vector<P> m;
        double bef = 0.0;
        rep(i, n){
            if(bef <= dp[i][j - 1]){
                m.push_back( P(dp[i][j - 1], i) );
                bef = dp[i][j - 1];
            }
        }
        rep(i, n){
            rep(k, m.size()){
                dp[i][j] = max(dp[i][j], m[k].first * vec[m[k].second][i]);
            }
        }
    }
}

double disp(double ans){
    ans = (int)(ans * 100 + 0.5);
    return ans / 100;
}

int main(){
    while(cin >>n >>m && n != 0 && m != 0){
        vec = vector< vector<double> >(n);
        rep(i, n){
            vec[i] = vector<double>(n);
            rep(j, n) cin >>vec[i][j];
        }
        dp = vector< vector<double> >(n);
        rep(i, n){
            dp[i] = vector<double>(m + 1, 0);
            dp[i][0] = 1.0;
            dp[i][1] = 1.0;
        }

        solve();
        double ans = 0.0;
        rep(i, n) if(ans < dp[i][m]) ans = dp[i][m];
        printf("%.2lf\n", disp(ans));
    }
    return 0;
}