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 <vector>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
using namespace std;
double key[100][100];
double table[100][100][100];

void Init(int n, int m){
	for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) for(int k = 0; k < m+1; k++)table[i][j][k] = 0;
}

void Init2(int n, int m){
	for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) for(int k = 0; k < m+1; k++){
		if(k==0) table[i][j][k] = 1.0;
		else table[i][j][k] = 0;
	}
}



double memo(int prev, int cur, int count, int limit, int kind){
	if(table[prev][cur][count]) return table[prev][cur][count];
	if(count==limit){
		table[prev][cur][count] = 1.0;
		return table[prev][cur][count];
	}
	double Max = 0;
	for(int i = 0; i < kind; i++) Max = max(Max, memo(i, prev, count+1, limit, kind));
	table[prev][cur][count] = Max*key[prev][cur];
	return table[prev][cur][count];
}

int main(){
	int n, m;
	while(cin >> n >> m && ((n!=0)||(m!=0))){
		Init2(n, m);
		for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) cin >> key[i][j];
		//for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) table[i][j][0] = memo(i, j, 1, m, n);

		for(int k = 1; k < m; k++) {
			double Max = 0;
			for(int i = 0; i < n; i++) for(int j = 0; j < n; j++){
				for(int l = 0; l < n; l++){
					Max = max(Max, table[l][i][k-1]);
				}
				table[i][j][k] = Max*key[i][j];
			}  
		}
		double maxc = 0;
		for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(maxc < table[i][j][m-1]) maxc = table[i][j][m-1];
		printf("%0.2f\n", maxc);
	}

	return 0;
}

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

int main(){
	int n, m;
	double dp[100][100], hiryou[100][100];
	while(cin >>n >>m){
		if(n == 0 && m == 0) break;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				cin >>hiryou[i][j];
			}
		}
		dp[0][0] = 1.0;
		dp[0][1] = 1.0;
		dp[0][2] = 1.0;
		for(int i = 1; i < m; i++){
			for(int j = 0; j < n; j++){
				dp[i][j] = 0.0;
				for(int k = 0; k < n; k++){
					if(dp[i - 1][k] * hiryou[k][j] > dp[i][j]) dp[i][j] = dp[i - 1][k] * hiryou[k][j];
				}
			}
		}
		double ans = 0.0;
		for(int i = 0; i < n; i++){
			if(dp[m - 1][i] > ans) ans = dp[m - 1][i];
		}
		printf("%.2f\n", ans);
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n,m;
  while(cin>>n>>m,n+m){
    vector<vector<double> > d(n,vector<double>(n));
    vector<double> now(n,1),past(n,1);
  
    rep(i,n)rep(j,n)scanf("%lf",&d[i][j]);
    rep(times,m-1){
      rep(i,n){
	now[j] = 0;
	rep(j,n){
	  // i is past , j is now
	  now[j] = max(now[j],past[i] * d[i][j]);
	}
      }
      //      rep(i,now.size())cout<<now[i]<<" ";cout<<endl;
      past = now;
    }
    double ret = -1;
    rep(i,now.size())ret=max(ret,now[i]);
    printf("%.2lf\n",ret);
  }
  
  
}

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

using namespace std;

#define EPS 1e-9

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