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 <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))){
		Init(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 <bits/stdc++.h>

using namespace std;

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define INF 1e9

int main(){
    while(true){
        int n,m;
        cin >> n >> m ;
        if(n==0 && m ==0)
            break;
        vector<vector<double> > bt(n,vector<double>(n));
        vector<vector<pair<double,int>> > dp(m);

        FOR(i,0,n){
            FOR(j,0,n){
                cin >> bt[i][j] ;
            }
            dp[0].push_back(pair<double,int>(1.0,i));
        }

        double ans = 0.0;
        FOR(i,0,n-1){
            FOR(j,0,m){
                FOR(k,0,dp[i].size()){
                    double g;
                    int f;
                    tie(g,f) = dp[i][k];
                    dp[i+1].push_back(pair<double,int>(g*bt[f][j],j));
                    ans = max(ans, g*bt[f][j]);
                }
            }
        }
        printf("%.2f\n",ans);
    }




    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
#define _(_1,_2,_3,N,...)N
#define pr(...) _(__VA_ARGS__,pr3,pr2,pr1)(__VA_ARGS__)
template<C T>void pr1(T a){cout<<a;ln;}
template<C T,C T2>void pr2(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr3(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n,m;
  while(cin >> m >> n && n) {
    double a[m][m];
    rep(i,m)rep(j,m) R a[i][j];
    double d[n][m];
    mem(d);
    rep(i,m) d[0][i]=1;
    REP(i,1,n) {
      rep(j,m) {
        rep(k,m) d[i][k]=max(d[i][k],d[i-1][j]*a[j][k]);
      }
    }
    double ans=0;
    rep(i,m) ans=max(ans,d[n-1][i]);
    printf("%.2f\n",ans);
  }
}

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  Main();return 0;
}

C++: #include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,b,n) for(int i=b;i<n;i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int n,m;
const int MAX_N =120;
const int MAX_M =120;
double dp[MAX_N][MAX_M];//dp[i][j]:=直前にjを与え、i回目に肥料を与えたときの最大の成長
double memo[MAX_N][MAX_N];
int main(){
	while(1){
		cin>>n>>m;
		if(n==0&&m==0){
			break;
		}
		for(int i =0;i <MAX_N;i++){
			for(int j =0;j <MAX_N;j++){
				dp[i][j] =0;
				memo[i][j]=0;
			}
		}
		rep(i,n){
			rep(j,n){
				cin>>memo[i][j];
			}
		}
		bool flag =false;
		if(m==1){
			printf("%.2f\n",1.00);
			continue;
		}

		rep(i,n)dp[1][i] =1;

		double ans =0;
		for(int i =1;i <m;i++){
			for(int k =0;k <n;k++){//直前
				for(int j =0;j <n;j++){//直後
					dp[i+1][j] =max(dp[i+1][j],dp[i][k]*memo[k][j]);
					if(dp[i+1][j]>ans){
						ans =dp[i+1][j];
					}
				}
			}
		}
		ans +=0.005;
		ans =ans*100;
		ans =(int)ans;
		ans =(double)ans/100;
		printf("%.2f\n",m==1?1:ans);
	}
	return 0;
}

C++: 
#include<iostream>
#include<algorithm>
#include<vector>
#include<iomanip>
using namespace std;
int main()
{
  cout<<setprecision(2);
  cout<<setiosflags(ios::fixed);
  int n,m,i,j,k;
  long double M;
  while(cin>>n>>m,n|m){
    vector< vector<long double> >manure(n,vector<long double>(n)),dp(m,vector<long double>(n,0.0));
    for(i=0;i<n;i++)for(j=0;j<n;j++)cin>>manure[i][j];
    for(j=0;j<n;j++)dp[0][j]=1.0;
    for(i=1;i<m;i++){
      for(j=0;j<n;j++){
	for(k=0;k<n;k++){
	  dp[i][j]=max(dp[i][j],dp[i-1][k]*manure[k][j]);
	}
      }
    }
    M=0.0;
    for(j=0;j<n;j++)M=max(M,dp[n-1][j]);
    cout<<M<<endl;
  }
}