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

package main

import (
	"bufio"
	"os"
	"strings"
	"strconv"
		"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 <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<30;

int main() {
  int n, m;
  while(cin >> n >> m, n||m) {
    double hi[n][n];
    REP(i,n)
      REP(j,n)
      cin >> hi[i][j];
    double dp[m][n];
    REP(i,n)
      dp[0][i] = 1;
    REP(i,m-1) {
      REP(j,n) {
        double ma = 0;
        REP(k,n) {
          ma = max(ma, dp[i][k] * hi[k][j]);
        }
        dp[i+1][j] = ma;
      }
    }
    double ma = 0;
    REP(i,n)
      ma = max(ma, dp[m-1][i]);
    printf("%.2f\n", ma);
  }
}

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<cmath>
#include<iomanip>
using namespace std;

int main()
{
  double d, c;
  int n, m;
  cout<<setprecision(2);
  cout<<setiosflags(ios::fixed);
  while (cin>>n>>m, n) {
    n *= n;
    c = 0.0;
    while (n-- > 0) {
      cin>>d;
      if (c < d) c = d;
    }
    cout<<pow(c, m-1)<<endl;
  }
  return 0;
}

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

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)

int main() {
  int N, M;
  while(cin >> N >> M && (N|M)) {
    double p[N][N]; rep(i, N) rep(j, N) cin >> p[i][j];
    vector<double> dp(N, 1.0), next(N);
    rep(m, M-1) {
      rep(i, N) {
	rep(j, N) {
	  next[j] = max(next[j], dp[i]*p[i][j]);
	}
      }
      dp = next;
    }
    printf("%.2f\n", *max_element(dp.begin(), dp.end()));
  }
  return 0;
}

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

# define MAX_N 100
# define MAX_M 100

int n, m;
double dp[MAX_N][MAX_M];

double board[MAX_M][MAX_M];

int main() {
	while (1) {
		std::cin >> n >> m;
		if (n == 0 && m == 0)
			break;
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < m; ++j)
				dp[i][j] = 0;
		for (int i = 0; i < m; ++i) {
			for (int j = 0; j < m; ++j)
				std::cin >> board[i][j];
		}
		std::fill(dp[0], dp[0] + m, 1);
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < m; ++j) {
				for (int k = 0; k < m; ++k) {
					dp[i][j] = std::max(dp[i][j], dp[i - 1][k] * board[k][j]);
				}
			}
		}
		double res = 0;
		for (int i = 0; i < m; ++i)
			res = std::max(res, dp[n - 1][i]);
		std::cout << std::setprecision(3) << res << std::endl;
	}
	return 0;
}

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

const double EPS = 1e-10;
int n, m;
//memo[i][j]: 直前にjを入れてi回目のときの最大倍率
//a[i][j]: 直前i
double a[101][101], memo[101][101];

double rec(int i, int j){
	if(memo[i][j] > -EPS){
		return memo[i][j];
	}

	if(i == m){
		return 1;
	}

	double res = 0;
	for(int u=1;u<=n;u++){
		res = std::max(res, a[j][u] * rec(i+1, u));
	}

	return memo[i][j] = res;
}

int main(){
	while(std::cin >> n >> m, n){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				std::cin >> a[i][j];
			}
		}

		for(int i=1;i<101;i++){
			a[0][i] = 1;
		}

		for(int i=0;i<101;i++){
			for(int j=0;j<101;j++){
				memo[i][j] = -1;
			}
		}
		
		printf("%.2f\n", rec(0, 0));
	}
}

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

double fig[100][100];
int n,m;

double serch(int kind,double point,int count){
	if(count==m)
		return point;
	double ans = 0.0;
	for(int i=0;i<n;i++){
		ans = max(ans,serch(i,point*fig[kind][i],count+1));
	}
	return ans;
}
int main()
{
	while(cin >> n >> m){
		if(!n && !m)
			break;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cin >> fig[i][j];
			}
		}
		double ans = 0.0;
		for(int i=0;i<n;i++){
			ans = max(ans,serch(i,1.0,1));
		}
		cout << setprecision(2)<< fixed << ans << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define F first
#define S second
#define INF 1 << 30

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int main(){
  int n, m;
  double dp[128][128];
  double g[128][128];
  while(scanf("%d%d", &n, &m) && n+m){
    rep(i, n) rep(j, n) scanf("%lf", &g[i][j]);

      memset(dp, 0, sizeof(dp));
    rep(i, n) dp[i][0] = 1.0;

    /*    rep(i, n){
      rep(j, m) printf("%.2lf ", dp[i][j]);
      puts("");
      }*/

    REP(i, 1, m){
      rep(j, n){
	rep(k, n){
	  dp[j][i] = max(dp[j][i], dp[k][i-1]*g[k][j]);
	  printf("%d %d %d %.2lf\n", i, j, k, g[k][j]);
	}
      }
      /*      rep(i, n){
	rep(j, m) printf("%.2lf ", dp[i][j]);
	puts("");
	}*/
    }

  /*    rep(i, n){
      rep(j, m) printf("%.2lf ", dp[i][j]);
      puts("");
      }*/
    double res = 0;
    rep(i, n) res = max(res, dp[i][m-1]);
    printf("%.2lf\n", res);
  }
  return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int m,n;
double a[100][100],b[100][100];
double f(int p,int q,double r){
  int i;
  double mx=0;
  if(p==m){
    mx=r;
  }else if(b[p][q]<r){
    b[p][q]=r;
    for(i=0;i<n;i++)
      mx=max(mx,f(p+1,i,r*a[q][i]));
  }
  return mx;
}
int main(){
  int i,j;
  double mx;
  while(cin>>n>>m&&n+m){
    for(i=0;i<n;i++)
      for(j=0;j<n;j++)
	cin>>a[i][j];
    memset(b,0,sizeof(b));
    mx=0;
    for(i=0;i<n;i++)
      mx=max(mx,f(1,i,1));
    printf("%.2lf\n",mx);
  }
  return 0;
}