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

package main

import (
	"bufio"
	"os"
	"strings"
	"strconv"
	"log"
	"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<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
double g[100][100],dp[100][100];
int main(){
    int n,m;
    while(scanf("%d%d",&n,&m),n||m){
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
                scanf("%lf",&g[i][j]);
        
        fill_n(dp[0],100,1.0);
        fill_n(dp[1],9900,0.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]*g[k][j]);

        printf("%.2f\n",*max_element(dp[m-1],dp[m-1]+n));
    }
    return 0;
}

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

using namespace std;

int main() {
	int n, m;
	while (cin >> n >> m) {
		if (n == 0 && m == 0) {
			break;
		}
		vector< vector<double> > hyou(n, vector<double>(n));
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cin >> hyou[i][j];
			}
		}
		vector< vector<double> > nae(m, vector<double>(n, 1.0));
		for (int i = 1; i < m; i++) {
			for (int j = 0; j < n; j++) {
				nae[i][j] = nae[i-1][0]*hyou[0][j];
				for (int k = 1; k < n; k++) {
					nae[i][j] = max(nae[i][j], nae[i-1][k]*hyou[k][j]);
				}
			}
		}
		double MAX = 0.0;
		for (int i = 0; i < n; i++) {
			MAX = max(MAX, nae[m-1][i]);
		}
		MAX *= 100.0;
		if (MAX-(double)((int)MAX) >= 0.5) {
			MAX += 1.0;
		} 
		MAX /= 100.0;
		printf("%.2f\n", MAX);
	}
	return 0;
}

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

using namespace std;

int n, m;
double grow[100][100];
double dp[100][3];//

int main() {
	while (cin >> n >> m, n * m) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cin >> grow[i][j];
			}
		}
		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++) {
				double M = 0;
				for (int k = 0; k < n; k++) {
					M = max(M, dp[i - 1][k] * grow[k][j]);
				}
				dp[i][j] = M;
			}
		}
		double ans = 0;
		for (int i = 0; i < m; i++) {
			ans = max(ans, dp[n - 1][i]);
		}
		int a = ans * 100;
		ans = a / 100;
		cout << fixed << setprecision(2) << ans << endl;
		for (int i = 0; i < m; i++)for (int j = 0; j < m; j++)grow[i][j] = 0;
		for (int i = 0; i < n; i++)for (int j = 0; j < m; j++)dp[i][j] = 0;
	}
	return 0;
}

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

double dp[101][101][101];//dp[i][j][k]=i?????????????????\??????j?????\?????\??????k?????¨??????????????????????????§???
double grow[101][101];//i=??´??????j=??????
		

int main(){
	while(1){
		int m,n;
		std::cin>>m>>n;
		if(m*n==0)break;
		for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)grow[i][j]=0;
		for(int i=2;i<=m;i++)for(int j=1;j<=m;j++)for(int k=1;k<=m;k++)dp[i][j][k]=0;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				std::cin>>grow[i][j];
			}
		}
		for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)dp[1][i][j]=1.0;
		for(int i=2;i<=m;i++){
			for(int j=1;j<=n;j++){
				for(int k=1;k<=n;k++){
					double a=0;
					for(int l=1;l<=n;l++){
						a=std::max(a,dp[i-1][l][k]);
					}
					dp[i][j][k]=a*grow[j][k];
				}
			}
		}
		double ans=0;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++)ans=std::max(ans,dp[m][i][j]);
		}
		std::cout<<std::fixed<<std::setprecision(2)<<ans<<std::endl;
	}
	return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define dump(o) { cerr << #o << " " << o << endl; }
#define dumpc(o) { cerr << #o; for (auto &e : (o)) cerr << " " << e; cerr << endl; }
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

#define MAX_M 101
#define MAX_N 100

signed main() {
	double a[MAX_N][MAX_N];
	double dp[MAX_M][MAX_N];
	for (int n, m; cin >> n >> m&&n;) {
		memset(dp, 0, sizeof(dp));
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cin >> a[i][j];
			}
		}

		for (int i = 0; i < n; i++) {
			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] * a[k][j]
					);
				}
			}
		}
		double ans = 0;
		for (int j = 0; j < n; j++) {
			ans = max(ans, dp[m - 1][j]);
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
double x[100][100], dp[101][100]; int n, m;
int main() {
	while (true) {
		cin >> n >> m; if (n == 0 && m == 0) { break; }m--;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++)cin >> x[i][j];
		}
		for (int i = 0; i < 101; i++) {
			for (int j = 0; j < 100; j++)dp[i][j] = 0.0;
		}
		for (int i = 0; i < 100; i++)dp[0][i] = 1.0;
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < n; j++) {
				for (int k = 0; k < n; k++) {
					dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] * x[j][k]);
				}
			}
		}
		double maxn = 0;
		for (int i = 0; i < 100; i++)maxn = max(maxn, dp[m][i]);
		printf("%.2lf\n", maxn);
	}
	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<eps)
#define SIZE 105
double dp[SIZE][SIZE];
int n,m;
double level[SIZE][SIZE];
int main()
{
	while(1)
	{
		scanf("%d %d",&n,&m);
		if(n==0&&m==0)break;
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				scanf("%lf",&level[i][j]);
			}
		}
		memset(dp,0,sizeof(dp));
		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++)
				{
					dp[i+1][k]=max(dp[i+1][k],dp[i][j]*level[j][k]);
				}
			}
		}
		double ans=0.0;
		for(int i=0;i<n;i++)ans=max(ans,dp[m][i]);
		ans*=100.0;
		printf("%.2f\n",((int)ans)/100.0);
	}
	return 0;
}