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<cmath>
#include<vector>

using namespace std;

const double eps = 1.0e-10;
double eq(double a, double b){ //a==b
  return abs(b-a)<eps;
}
double gt(double a, double b){ //a>b
  return !eq(a,b) && a > b;
}

int main(){
  while(true){
    int n,m;
    double answer = -1;
    cin >> n >> m;
    if( n == 0 && m == 0 ) break;
    double table[n][n];
    for(int i = 0; i < n; ++i){
      for(int j = 0; j < n; ++j){
	cin >> table[i][j];
      }
    }
    vector<int> colors;
    vector<double> greedy;
    for(int i = 0; i < n; ++i){
      colors.push_back( i );
      greedy.push_back( 1.0 );
    }

    for(int k = 0; k < m-1; ++k){
      vector<int> next_colors;
      vector<double> next_greedy;
      for(int i = 0; i < colors.size(); ++i){
	double maximum = -1;
	for(int j = 0; j < n; ++j){
	  double t = greedy[i] * table[ colors[i] ][ j ];
	  if( gt( t, maximum ) ){
	    maximum = t;
	  }
	}
	for(int j = 0; j < n; ++j){
	  double t = greedy[i] * table[ colors[i] ][ j ];
	  if( eq( t, maximum ) ){
	    next_colors.push_back( j );
	    next_greedy.push_back( t );
	  }
	}
      }
      //colors.clear();
      //greedy.clear();
      for(int i = 0; i < next_colors.size(); ++i){
	colors.push_back( next_colors[i] );
	greedy.push_back( next_greedy[i] );
      }
    }
    
    for(int i = 0; i < greedy.size(); ++i){
      if( gt( greedy[i], answer ) )
	answer = greedy[i];
    }
    printf("%.2lf\n",answer);

  }
  return 0;
}

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;
//vector<double> matrix[110];
double matrix[110][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,test=0.0;
 
 
  for(int i=0;i<n;i++){   
    
    //HANMA = max(HANMA,rec(i,counter-1)*matrix[next][i]);
    test = rec(i,counter-1)*matrix[next][i];
    if(test > HANMA)HANMA = test;
  }  
 
  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();
    
    for(int i=m;i>=0;i--)for(int j=0;j<n;j++)dp[j][i] = -10;
    for(int i=0;i<n;i++)dp[i][0] = dp[i][1] = 1;
 
 
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	//cin >> matrix[i][j];
	scanf("%lf",&matrix[i][j]);
	//matrix[i].push_back(In);
      }
    }
 

    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 <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);
    double ret=0;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	cin >> t[i][j];
      }
    }
    printf("%.5lf\n", solve(0,0));
  }
}

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

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

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

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;
const int INF = 1 << 30;

int main()
{
	long double T[128][128], dp[128][128];
	int n, m;

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

		for(int i = 0; i < n; i++)
		{
			for(int j = 0; j < n; j++)
			{
				cin >> T[i][j];
			}
		}
		
		memset(dp, -1, sizeof(dp));
	
		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++)
			{
				//dp[i][j] = -1.0;
				for(int k = 0; k < n; k++)
				{
					//dp[i][j] : i回目で肥料jを使った時の最大の苗木の大きさ
					dp[i][j] = max(dp[i][j], dp[i-1][k]*T[k][j]);
				}
			}
		}

		long double res = -1; 
		for(int i = 0; i < n; i++)
		{
			res = max(res, dp[m-1][i]);
		}
	
		printf("%.2Lf\n",res);
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(2);
  
  int n, m;
  while (cin >> n >> m, n) {
    double g[110][110];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        cin >> g[i][j];
      }
    }
    double dp[110][110] = {};
    fill_n((double*)dp, 110, 1);
    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][j] = max(dp[i + 1][j], dp[i][k] * g[k][j]);
        }
      }
    }
    double ans = 0;
    for (int i = 0; i < n; i++) {
      ans = max(ans, dp[m - 1][i]);
    }
    cout << ans << endl;
  }

  return 0;
}