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 <algorithm>
using namespace std;
#define rep(i,k,n) for(int i = k ; i < n ; i++ )
double G[101][101];
int main(){
  int n,m;
  while( cin >> n >> m,n+m){

    rep(i,1,n+1)
      rep(j,1,n+1)cin >> G[i][j];

    double dp[101][101];

    fill(dp[0],dp[101],0);

    rep(j,0,n+1)dp[1][j] = 1;

    double mx = 0;

    rep(i,2,m+1){
      rep(j,1,n+1){
	rep(k,1,n+1){
	  dp[i][j] = max(dp[i][j],dp[i-1][k] * G[k][j]);
	}
      }
    }

    rep(j,1,n+1)mx = max(mx,dp[m][j]);
    printf("%.2f\n",mx);

  }
  return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int n,m;
double ma,s[110][110];
void func(int pre,int cnt,double now){
	cnt++;
	if(cnt!=m){
		for(int i=0;i<n;i++){
			func(i,cnt,now*s[pre][i]);
		}
	}
		else {
		if(ma<now)
			ma=now;
	}
}
int main(){
	while(cin>>n>>m,n||m){
		ma=0;
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
		scanf("%lf",&s[i][j]);
		for(int i=0;i<n;i++)
			func(i/*OñÌÔ*/,0/*JEg*/,1.0/*»ÝÌ¬·*/);
		printf("%.2lf\n",ma);;
	}
	return 0;
}

C++: #include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include <string>
#include <complex>
#include <functional>
#include<stdio.h>
using namespace std;
typedef pair<int,int> P;
double dat[100][100];
double dp[200][100];//動的計画法
int main(){
    int a,b;
    while(cin>>a>>b,a){
        for(int i=0;i<a;i++){
            for(int j=0;j<a;j++){
                cin>>dat[i][j];
            }
        }
        for(int i=0;i<a;i++)dp[0][i]=1;
        for(int i=1;i<b;i++){
            for(int j=0;j<a;j++){
                double max=0;
                for(int k=0;k<a;k++){
                    if(max<dp[i-1][k]*dat[k][j]){
                        max=dp[i-1][k]*dat[k][j];
                    }
                }
                dp[i][j]=max;
            }
        }
        double ret=0;
        for(int i=0;i<a;i++){
            if(ret<dp[b-1][i])ret=dp[b-1][i];
        }
        printf("%.2lf\n",ret);
    }
}

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){
	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 <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];

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

double memo(int cur, int count, int limit, int kind){
	if(table[cur][count]) return table[cur][count];
	if(count==limit) return 1.0;
	double Max = 0;
	int prev = 0;
	for(int i = 0; i < kind; i++){
		double tmp = memo(i, count+1, limit, kind);
		if(Max <= tmp){
			//if(Max*key[prev][cur] < tmp*key[i][cur]){
				Max = tmp;
				prev = i;
			//}
		}
	}
	table[cur][count] = Max*key[prev][cur];
	return table[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++) table[i][0] = memo(i, 1, m, n);
		double max = 0;
		for(int i = 0; i < n; i++) if(max < table[i][0]) max = table[i][0];
		printf("%0.2f\n", max);
	}

	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];
			}
		}
		rep(i,n)dp[1][i] =1.00;

		double ans =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][j] =max(dp[i+1][j],dp[i][k]*memo[k][j]);
				}
			}
		}
		rep(i,n)ans=max(ans,dp[m][i]);
		/*
		ans +=0.005;
		ans =ans*100;
		ans =(int)ans;
		ans =(double)ans/100;
		 */
		printf("%.2lf\n",ans);
	}
	return 0;
}