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<cstdio>
#include<algorithm>
#include<vector>
#include<cassert>
#include<cmath>
#define EPS 1e-10
using namespace std;
typedef pair<double,int> P;
int m,n;
double total;
double dp[110][110];
int Just;
bool al;
vector<P> stren;
vector<double> matrix[110];
double rec(int next,int counter){
  if(dp[next][counter] > 0)return dp[next][counter];
  if(counter  == 0){
    return 1.0;
  }
  double HANMA = 0.0;
  double Maax = stren[next].first;
 
  for(int i=0;i<n;i++){   
    //if(fabs(Maax-matrix[next][i]) < EPS){
      HANMA = max(HANMA,rec(i,counter-1)*matrix[next][i]);
      // }
  }  
 
  dp[Just][counter] = HANMA;
  return HANMA;
}


int main(){
  
  double In;
 
  while(cin >> n >> m && n && m){
    for(int i=0;i<=n;i++)matrix[i].clear();
    stren.clear();
    for(int i=109;i>=0;i--)for(int j=0;j<110;j++)dp[j][i] = -10;
    for(int i=0;i<110;i++)dp[i][0] = dp[i][1] = 1;
    double MaX[n+1];
    int Pos[n+1];
    for(int i=0;i<n;i++)MaX[i] = 0;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	cin >> In;
	matrix[i].push_back(In);
	if(MaX[i] < In+EPS){
	  MaX[i] = In;
	  Pos[i] = j;
	}
      }
    }
  
    for(int i=0;i<n;i++){
      stren.push_back(P(MaX[i],Pos[i]));
    }

    double ans = -1;
 
  
      for(int I=0;I<n;I++){
	Just = I;
	double tes = rec(I,m);
	ans = max(ans,dp[Just][m]);
      }
    

      //for(int i=1;i<=m;i++)cout << dp[0][i] << " ";
      //cout << endl;

    printf("%.2f\n",ans);

  }
  return 0;
}

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; 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;
			}
		}
		else if(Max < tmp){
			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, 0, m-1, 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 <iostream>
#include <cmath>
using namespace std;

const int MAX_N = 100, MAX_M = 100;
const double EPS = 1e-10;

int n,m;
long double g[MAX_N][MAX_N], dp[2][MAX_N];

int main()
{
    int m, n;
    while(cin >> n >> m && n) {
        for(int i = 0; i < n; i++) 
            for(int j = 0; j < n; j++) 
                cin >> g[i][j];

        for(int i = 0; i < n; i++) 
            dp[0][i] = 1.0;
        
        for(int i = 0; i < m - 1; i++) {
            for(int j = 0; j < n; j++) {
                for(int k = 0; k < n; k++) {
                    dp[(i+1) % 2][k] = max(dp[(i+1) % 2][k], dp[i % 2][j] * g[j][k]);
                }
            }
        }
        long double ret = 0.0;
        for(int i = 0; i < n; i++) 
            ret = max(ret, dp[(m-1) % 2][i]);
        printf("%.2Lf\n", ret);

    }
    
}

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

using namespace std;

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

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 < n; i++)dp[0][i] = 1;
		for (int i = 1; i < m; i++) {
			for (int j = 0; j < n; 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 < n; i++) {
			ans = max(ans, dp[m - 1][i]);
		}
		cout << fixed << setprecision(2) << ans + 0.005 << endl;
		for (int i = 0; i < n; i++)for (int j = 0; j < n; j++)grow[i][j] = 0;
		for (int i = 0; i < m; i++)for (int j = 0; j < n; j++)dp[i][j] = 0;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int n,m;
	while(cin >> n >> m , n){
		double dp[101][101] = {0};
		double rate[101][101] = {0};
		rep(i,n)rep(j,n)
			cin >> rate[i][j];
		rep(i,n)dp[0][i] = 1.0;
		rep(x,m-1){
			rep(i,n)
				rep(j,n)
					dp[x+1][j] = max(dp[x][i]*rate[i][j],dp[x+1][j]);
		}
		double ans = 0;
		rep(i,n) ans = max(ans,dp[m-1][i]);
		printf("%.2lf\n",ans);
	}
}