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<algorithm>
#include<iomanip>

double dp[101][101];//dp[i][j]=i??????????????\?????\??????j?????¨??????????????????????????§???
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++)dp[i][j]=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++)dp[1][i]=1.0;
		for(int i=2;i<=m;i++){
			for(int j=1;j<=n;j++){
				double a=0;
				int b=0;
				for(int k=1;k<=n;k++){
					a=std::max(a,dp[i-1][k]);
					b=k;
				}
				dp[i][j]=a*grow[b][j];
			}
		}
		double ans=0;
		for(int i=1;i<=n;i++){
			ans=std::max(ans,dp[m][i]);
		}
		std::cout<<std::fixed<<std::setprecision(2)<<ans<<std::endl;
	}
	return 0;
}

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

using namespace std;

int n,m;
double dp[101][101];
double t[101][101];

double solve(int times, int prev){
  if(dp[times][prev] != -1) return dp[times][prev];
  if(times == m) return dp[times][prev] = 1;

  double tmp=-1;
  for(int i=0;i<n;i++){
    if(times == 0){
      tmp = max(tmp, solve(times+1, i) * 1);
    }else{
      tmp = max(tmp, solve(times+1, i) * t[prev][i]);
    }
  }
  
  return dp[times][prev] = tmp;
}

int main(void){
  while(cin >> n >> m){
    if(!(n|m)) break;
    fill((double *)dp, (double *)dp+101*101, -1);
    int ret;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	cin >> t[i][j];
      }
    }
    ret = solve(0,0) * 1000;
    if(ret%10 >= 5){
      ret += 10;
    }
    ret /= 10;
    printf("%.2lf\n", (double)ret / 100);
  }
}

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    while(true){
	int m,n;
	cin >> n >> m;
	vector< vector<double> > d(n,vector<double>(n,0.0) );
	if(n == 0 && m == 0) break;
	REP(i,n)REP(j,n) cin >> d[i][j];
	double ans = 0.0;
	vector<double> a(n);
	double dp[2][101];
	REP(i,2)REP(j,101) dp[i][j] = 0;
	REP(i,101) dp[0][i] = 1;
	REP(i,m-1){
	    REP(j,101) dp[1][i] = 0;

	    REP(j,n){
		dp[1][j] = dp[0][0] * d[j][0];
		REP(k,n){
		    dp[1][j] = max(dp[1][j],dp[0][k] * d[j][k]);
		}
	    }
	    swap(dp[0],dp[1]);
	}
	REP(i,n) ans = max(dp[0][i],ans);
	int t = ans * 1000;
	t = t % 10;
	if(t >= 5) ans += 0.01;
	printf("%.2f\n",ans);
    }
    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 <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<n;i++){
		dp[0][i]=1;
	}
	for(int i=1;i<m;i++){
		for(int j=0;j<n;j++){
			double tmp=0;
			for(int k=0;k<n;k++){
				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[m-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;
	}
}

C++: #include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
main(){
  int n,m;
  while(cin>>n>>m,n){
    double t[n][m],mm=0,dp[m][n]={};
    r(i,n)r(j,n)cin>>t[i][j];
    r(i,n)dp[0][i]=1;
    for(int i=1;i<m;i++)r(j,n)r(k,n)
      dp[i][j]=max(dp[i][j],dp[i-1][k]*t[k][j]);
    r(i,n)mm=max(mm,dp[m-1][i]);
    printf("%.2f\n",mm);
  }
}