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 <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("%.3lf ", dp[i][j]);
      puts("");
      }*/
    double res = 0;
    rep(i, n) res = max(res, dp[i][m-1]);
    res *= 100;
    int tmp = (int)res + 0.5;
    res = (double)tmp / 100;
    printf("%.2lf\n", res);
  }
  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[0][i] = 1.0;
			for (int j = 1; j < 200; j++){
				dp[j][i] = 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++){
//					printf("%lf\n", dp[i][j] * growth[k][j]);
					dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] * 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("%.2lf\n", maxi);
	}
	
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
	while(1){
		int n,m;
		cin>>n>>m;
		if(n==0 && m==0)break;
		
		double sei[101][101];//n^n
		double dp[101][101]={};//m*n
		double ans=0.0;
		
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cin>>sei[i][j];
			}
		}
		
		/*for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cout<<sei[i][j]<<" ";
			}
			cout<<endl;
		}*/
		
		
		for(int i=0;i<n;i++)
			dp[1][i]=1.0;
		for(int i=1;i<=m;i++){
			for(int j=0;j<n;j++){
				for(int k=0;k<n;k++){
					//cout<<i<<" "<<j<<" "<<k<<endl;
					if(dp[i][j]*sei[j][k]>=dp[i+1][k])
					dp[i+1][k]=dp[i][j]*sei[j][k];
				}
			}
		}
		for(int i=0;i<n;i++)
			ans=max(dp[m][i],ans);
		/*for(int i=0;i<m;i++){
			for(int j=0;j<n;j++){
				cout<<dp[i][j]<<" ";
			}
			cout<<endl;
		}*/
		printf("%.2f\n",ans);
		//cout<<ans<<endl;
		
	}
	
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

#define MAX 150

int main()
{
    int N, M;
    while (cin >> N >> M, N) {
        double g[N][N];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                cin >> g[i][j];
            }
        }
        
        double dp[MAX][MAX];
        for (int i = 0; i < MAX; i++) {            
            for (int j = 0; j < MAX; j++) {
                dp[i][j] = (j == 0 ? 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[k][i+1] = max(dp[k][i+1],
                                       dp[j][i] * g[j][k]);
                }
            }
        }
        
        double res = 0;
        for (int i = 0; i < N; i++) {
            res = max(res, dp[i][M-1]);
        }
        printf("%.2f\n", res);
    }
    return 0;
}

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

using namespace std;
const int MAX = 101;

double item[MAX][MAX];
double ans[MAX][MAX][MAX];

int n,m;

void solve(){
  for(int i = 0; i < 2; i++)
    for(int j = 0; j < MAX; j++)
      fill(ans[i][j],ans[i][j]+MAX,1.0);

  
  for(int i = 2; i <= m; i++)
    for(int j = 0; j < n; j++)
      for(int k = 0; k < n; k++)
	for(int l = 0; l < n; l++)
	  ans[i][j][k] = max(ans[i][j][k],ans[i-1][l][j]*item[j][k]);



  double out = 0.0;

  for(int i = 0; i < n; i++)
    for(int j = 0; j < n; j++)
      out = max(out,ans[m][i][j]);
 
  printf("%.2f\n",out);
}

int main(){
  while(cin >> n >> m && n+m){

    memset(ans,0,sizeof(ans));

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

    solve();
  }
  return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999
//#define INF (1LL<<59)


int main(){
	int n,m;
	while(cin>>n>>m&&(n||m)){
		double table[101][101];
		rep(i,n) rep(j,n) cin>>table[i][j];
		
		double dp[101][101];
		rep(i,101)rep(j,101)dp[i][j] = -1;
		rep(i,n) dp[0][i] = 1;
		
		for(int i=1;i<m;i++){
			rep(j,n){
				rep(k,n){
					dp[i][j] = max( dp[i-1][k]*table[k][j] , dp[i][j] );
				}
			}
		}
		
		double ans = -1;
		rep(i,n){
			ans = max(ans,dp[m-1][i]);
		}
		printf("%.10lf\n",ans);
	}
}

C++: p#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 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++){
				int tmp=0;
				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;
	}
}