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 <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

int main(){
  int n,m;
  double table[100][100];
  while(cin>>n>>m,n){
    REP(i,n)REP(j,n)cin>>table[i][j]; //j->i
    vector<double> dp(n,1.0);
    REP(i,m-1){
      vector<double> ndp(n);
      REP(j,n)REP(k,n)ndp[k] = max(ndp[k],table[k][j] * dp[j]); //j->k
      dp = ndp;
    }
    double ans = 0;
    REP(i,n)ans = max(ans,dp[i]);
    /*
    int intans = ans * 1000;
    if(intans % 10 < 5) {
      intans -= intans % 10;
    }else{
      intans += (10 - intans % 10);
    }
    ans = (double)intans / 1000;
    */
    printf("%0.2lf\n",ans);
  }
  return 0;
}

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

int main()
{
	double memo[100][100];
	double data[100][100];
	int n, m;

	while (true)
	{
		cin >> n >> m;
		if (n + m == 0) return 0;

		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < n; j++)
			{
				cin >> data[i][j];
			}
		}

		for (int i = 0; i < m; i++)
		{
			for (int j = 0; j < n; j++)
			{
				memo[i][j] = -1;
				if (i == 0) memo[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++)
				{
					memo[i][j] = max(memo[i][j], memo[i - 1][k] * data[k][j]);
				}
			}
		}

		double Max = -1;
		for (int i = 0; i < n; i++)
		{
			Max = max(Max, memo[m - 1][i]);
		}
		printf("%.2f\n", Max);
	}

	return 0;
}

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

using namespace std;
const int INF = 1000000;

double data[100][100];
double dp[100][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][mm]!=-1)
	return dp[i][j][mm];
      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][mm]=tmp;
	  return tmp;
	}
    }
}

int main()
{

  for(;cin>>n>>m,n;)
    {
      for(int i=0;i<100;i++)
	for(int j=0;j<100;j++)
	for(int mm=0;mm<100;mm++)
	  {
	    dp[i][j][mm]=-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 <cstdio>
#include <algorithm>
using namespace std;

int main(){
	int n, m;
	while( scanf("%d %d", &n, &m) , n || m ){
		// g[prev][now] := 成長度
		double g[101][101];
		
		for(int y=0 ; y < n ; y++ ){
			for(int x=0 ; x < n ; x++ ){
				scanf("%lf", &g[y][x] );
			}
		}
		
		// dp[i][prev] := 直前の肥料 prev で i 回の肥料を与えた時の苗木
		double dp[101][101] = {0};
		for(int i=0 ; i < n ; i++ ){
			dp[1][i] = 1.0; 
		}
		
		for(int i=1 ; i < m ; i++ ){
			for(int prev=0 ; prev < n ; prev++ ){
				for(int now=0 ; now < n ; now++ ){
					dp[i+1][now] = max( dp[i+1][now] , dp[i][prev] * g[prev][now] );
				}
			}
		}
		double ans = 0.0;
		for(int i=0 ; i < n ; i++ ){
			ans = max( ans , dp[m][i] );
		}
		printf("%.2f\n", ans);
	}
}

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]; // dp[times][cur]

signed main()
{
	int N, M;
	
	while (cin >> N >> M, N || M) {
		memset(dp, 0, sizeof(dp));

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

		rep(i, N) 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][k] * table[k][j]);
                }
			}
		}

        double ans = 0;

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

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

C++: #include <iostream>
#include<iomanip>
#include<algorithm>
#define shosu(x) fixed<<setprecision(x)
using namespace std;

int n,m;
double ef[105][105];

double func(){
	double tmp=0,ans=0,dp[105][105]={0};
	for(int i=0;i<m;i++){
		dp[0][i]=1;
	}
	for(int i=1;i<n;i++){
		for(int j=0;j<m;j++){
			for(int k=0;k<m;k++){
				tmp=max(tmp,dp[i-1][k]*ef[k][j]);
			}
			dp[i][j]=tmp;
		}
	}
	for(int i=0;i<m;i++){
		ans=max(ans,dp[n-1][i]);
	}
	return ans;
}

int main(){
	cout<<shosu(2);
	while(1){
		cin>>n>>m;
		if(n==0&&m==0) break;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cin>>ef[i][j];
			}
		}
		cout<<func()<<endl;
	}
}