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<algorithm>
#include<math.h>
#include<stdio.h>
using namespace std;

int main(void){
	double dp[100][100];	// [回数][種類]
	double table[100][100];
	int N, T;

	while(true){
		cin >> T >> N;
		if( T == 0 && N == 0)
			break;
		for(int bef=0; bef<T; bef++)
			for(int cur=0; cur<T; cur++)
				cin >> table[bef][cur];

		// init
		for(int n=0; n<N; n++)
			for(int t=0; t<T; t++)
				dp[n][t] = n == 0 ? 1 : 0;
		
		// calc
		for(int n=0; n<N-1; n++){
			for(int tcur=0; tcur<T; tcur++){
				for(int taft=0; taft<T; taft++){
					dp[n+1][taft] = max(dp[n+1][taft], dp[n][tcur]*table[tcur][taft]);
				}
			}
		}

		double res = 0;
		for(int t=0; t<T; t++)
			res = max(dp[N-1][t], res);

		res = res * pow((double)10, 2);
		res = (double)(int)(res + 0.5);
		res = res * pow((double)10, -2);


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

C++: #include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
/*
肥料の種類	n	<=100
与える回数	m	<=100
*/
int main(){
	
	for(int n,m;cin>>n>>m,n;){
		double data[100][100];//直前/投与
		double now[100],tmp[100];
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cin>>data[i][j];
			}
		}
		for(int i=0;i<n;i++)now[i]=tmp[i]=1.0;
		for(int i=1;i<m;i++){
			for(int k=0;k<n;k++){//直後
				for(int j=0;j<n;j++){//直前
					if(!k)tmp[j]=now[k]*data[k][j];
					else tmp[j]=max(tmp[j],now[k]*data[k][j]);
				}
			}
			for(int j=0;j<n;j++)now[j]=tmp[j];
		}
		for(int i=1;i<n;i++){
			now[0]=max(now[0],now[i]);
		}
		printf("%.2f\n",now[0]);
	}
	
	return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#define ll long long int
#define ld long long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> P;

string str;

int main()
{
  int n,m;
  int i,j,k;
  double dp[105][105];
  double grow[105][105];
  int maxi[105];//テヲツ按静ゥツ閉キテ」ツ?古ヲツ慊?・ツ、ツァテ」ツ?ォテ」ツ?ェテ」ツつ凝」ツ?ィテ」ツ?催」ツ?ョテァツ崢エテ・ツ可催」ツ?ョティツつ・テヲツ鳴?

  while(1){
    cin>>n>>m;
    if(n==0 && m==0)break;

    rep(i,n)rep(j,n)
      cin>>grow[i][j];

    double temp;
    int tempi;
    rep(j,n){
      temp=0;
      rep(i,n)
        if(temp<grow[i][j]){
	  temp=grow[i][j];
	  tempi=i;
	}
      maxi[j]=tempi;
    }

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

    for(i=1;i<m;i++)
      for(j=0;j<n;j++){
	temp=0;
	rep(k,n)
	  temp=max(temp,dp[i-1][k]*grow[k][j]);
	dp[i][j]=temp;
      }
      
    double sum=0;

    rep(j,n)
      sum=max(sum,dp[m-1][j]);
 
    printf("%.2f\n",sum);
  }

}

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

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) rep(j, N) dp[0][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) {
					dp[i][j][k] = max(dp[i][j][k], *max_element(dp[i - 1][k], dp[i - 1][k] + N) * table[k][j]);
				}
			}
		}

		double ans = 0;

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

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

C++: #include <algorithm>
#include <map>
#include <vector>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define IREP(it,array) for(vector<int>::iterator it=array.begin(); it!=array.end(); ++it)
#define PREP(it,array) for(vector<P>::iterator it=array.begin(); it!=array.end(); ++it)
#define SREP(it,array) for(vector<string>::iterator it=array.begin(); it!=array.end(); ++it)

#define MP       make_pair
#define PB       push_back
#define ALL(x)   (x).begin(),(x).end()

const int INF = 1<<29;
const double EPS = 1e-9;
double zero(double d){
  return d < EPS ? 0.0 : d;
}

typedef long long LL;
typedef pair<int,int> P;






int main()
{
  cout.setf(ios::fixed, ios::floatfield);
  cout.precision(2);

  int n,m;
  while( cin>>n>>m, n ){
    double g[n][n];
    REP(i,n){
      REP(j,n){
	double t;
	cin >> t;
	g[i][j] = t;
      }
    }

    double dp[m+1][n];
    memset( dp, 0, sizeof(dp) );
    REP(i,n)
      dp[0][i] = 1.0;

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

    res *= 100;
    res += 0.5;
    res = int(res);
    res /= 100;

    cout << res << endl;
  }


  return 0;
}