Go: // n×nの成長度表に現れる数字を重複を許してm-1個選んで掛け合わせる時の最大値を求める
// ->掛け算型のDP

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

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 <iomanip>

using namespace std;
const int INF = 1000000;

double data[100][100];
double dp[100][100];
int n,m;

double check(int i,int mm)
{
  if(i==-1)
    {
      double tmp=1.0;
      if(mm>0)
	for(int xx=0;xx<n;xx++)
	{
	  tmp=max(tmp,check(xx,mm-1));
	}
      return tmp;
    }
  else
    {
      if(mm<0)
	return -INF;
      else if(mm==0)
	return 1.0;
      else if(dp[i][mm]!=-1)
	return dp[i][mm];
      else
	{
	  double tmp=check(0,mm-1)*data[i][0];
	  for(int xx=1;xx<n;xx++)
	    {
	      tmp=max(tmp,check(xx,mm-1)*data[i][xx]);
	    }
	  dp[i][mm]=tmp;
	  return tmp;
	}
    }
}

int main()
{

  for(;cin>>n>>m,n;)
    {
      for(int i=0;i<100;i++)
	for(int mm=0;mm<100;mm++)
	  {
	    dp[i][mm]=-1.0;
	  }
      for(int i=0;i<n;i++)
	for(int j=0;j<n;j++)
	  {
	    double tmp;
	    cin>>tmp;
	    data[i][j]=tmp;
	  }
      double ans=check(-1,m);
      
      cout<< fixed<<setprecision(2)<< ans << endl;
      
    }
}

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

using namespace std;


int main() {
  
  int N, M;
  
  while(cin >> N >> M && (N|M)) {
    vector<vector<double> > p(N, vector<double>(N, 0));
      
    for(int i=0; i<N; i++) for(int j=0; j<N; j++) cin >> p[i][j];
      
    vector<vector<double> > dp(M, vector<double>(N, 0));
    for(int i=0; i<N; i++) dp[0][i] = 1.0;
	
    for(int k=1; k<M; k++)
      for(int i=0; i<N; i++)
	for(int j=0; j<N; j++)
	  dp[k][i] = max(dp[k][i], dp[k-1][j]*p[j][i]);
    
    double res = 0.0;
    for(int i=0; i<N; i++) res = max(res, dp[M-1][i]);
    
    printf("%.2f\n", res);
  }  
  
  return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define dump(o) { cerr << #o << " " << o << endl; }
#define dumpc(o) { cerr << #o; for (auto &e : (o)) cerr << " " << e; cerr << endl; }
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

#define MAX_M 101
#define MAX_N 100

signed main() {
	cout << fixed << setprecision(2);
	double a[MAX_N][MAX_N];
	double dp[MAX_M][MAX_N];
	for (int n, m; cin >> n >> m&&n;) {
		memset(dp, 0, sizeof(dp));
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cin >> a[i][j];
			}
		}

		for (int i = 0; i < n; i++) {
			dp[0][i] = 1.0;
		}

		for (int i = 1; i < m; i++) {
			for (int j = 0; j < n; j++) {
				for (int k = 0; k < n; k++) {
					dp[i][j] = max(
						dp[i][j],
						dp[i - 1][k] * a[k][j]
					);
				}
			}
		}
		double ans = 0;
		for (int j = 0; j < n; j++) {
			ans = max(ans, dp[m - 1][j]);
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#define ll long long int
#define ld long long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> P;

string str;

int main()
{
  int n,m;
  int i,j,k;
  double dp[105][105];
  double grow[105][105];
  int maxi[105];//??????????????§???????????¨????????´????????\???

  while(1){
    cin>>n>>m;
    if(n==0 && m==0)break;

    rep(i,n)rep(j,n)
      cin>>grow[i][j];

    double temp;
    int tempi;
    rep(j,n){
      temp=0;
      rep(i,n)
        if(temp<grow[i][j]){
	  temp=grow[i][j];
	  tempi=i;
	}
      maxi[j]=tempi;
    }

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

    for(i=1;i<n;i++)
      for(j=0;j<n;j++){
	temp=0;
	rep(k,n)
	  temp=max(temp,dp[i-1][k]*grow[k][j]);
	dp[i][j]=temp;
      }
      
    double sum=0;

    rep(j,n)
      sum=max(sum,dp[n-1][j]);
 
    printf("%.2f\n",sum);
  }

}

C++: #include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>
  
int n, m;
double grow[100][100];
double dp[110][110];
  
int main() {
    while(std::cin >> n >> m, n + m) {
      
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            std::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) {
            dp[i][j] = 0.;
        }
    }
  
    for(int i = 1; i < m; ++i) {
        for(int j = 0; j < n; ++j) {
            for(int k = 0; k < n; ++k) {
                dp[i][j] = std::max(dp[i][j], dp[i - 1][k] * grow[k][j]);
            }
        }
    }
  
    printf("%.2lf\n", ((long long)(*std::max_element(dp[m - 1], dp[m - 1] + n) * 100 + 0.5)) / 100.);
  
  
    }
}

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

using namespace std;

int main()
{
	int n, m, c[100], p;
	double a[100][100], b[100], max;
	
	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 >> a[i][j];
			}
			c[i] = i;
		}
		fill(b, b+n, 1.0);
	
		for(int k = 1; k < m; k++){
			for(int i = 0; i < n; i++){
				max = 0.0;
				for(int j = 0; j < n; j++){
					if(max < a[c[i]][j]){
						max = a[c[i]][j];
						p = j;
					}
				}
				b[i] *= max;
				c[i] = p;
			}
		}
		sort(b, b+n);
		
		printf("%.2f\n", b[n-1]);
	}
	
	return 0;
}