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 <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()
{
	double T[128][128], dp[128][128];
	int n, m;

	while(cin >> m >> n)
	{
		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, 0, sizeof(dp));
		fill(dp[0], dp[0]+m, 1.0);

		for(int i = 1; i < n; i++)
		{
			for(int j = 0; j < m; j++)
			{
				for(int k = 0; k < m; k++)
				{

					//dp[i][k] : i回目で肥料jを使った時の最大の苗木の大きさ
					dp[i][k] = max(dp[i][k], dp[i-1][j]*T[k][j]);
				}
			}
		}

		double res = 0; 
		for(int i = 0; i < m; i++)
		{
			res = max(res, dp[n-1][i]);
		}
	
		res *= 100;
		res = int(res+0.5);
		res /= 100;

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

C++: #include <cstdio>
#include <algorithm>
using namespace std;
int main() {
    int n,m;
    while (scanf("%d%d",&n,&m)) {
        if (!n&&!m) break;
        double grow[n][n], dp[m][n];
        for (int i=0; i<n; i++) for (int j=0; j<n; j++) scanf("%lf",&grow[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++) {
                dp[i][j]=0.0;
                for (int k=0; k<n; k++) dp[i][j]=max(dp[i][j], dp[i-1][k]*grow[k][j]);
            }
        }
        double res=0.0;
        for (int i=0; i<n; i++) res=max(res, dp[m-1][i]);
        printf("%.2lf\n",res);
    }
}

C++: #include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

typedef vector <double> VD;
typedef vector <VD> VVD;

VVD C;	// cost
VD prev, next;
int n, m;	// ì¿ð^¦éñ
int i, j, k;

double solve()
{
	double answer = -1.0;
	for ( i = 0; i < n; i++ ) prev[i] = 1.0;
	for ( k = 1; k < m; k++ )
	{
		for ( i = 0; i < n; i++ )
		{
			next[i] = -1.0;
			for ( j = 0; j < n; j++ )
			{
				double tmp = prev[j] * C[j][i];
				next[i] = max( next[i], tmp );
			}
		}
		prev = next;
	}
	for ( i = 0; i < n; i++ ) answer = max( answer, prev[i] );
	return answer;
}

int main( void )
{
	C = VVD( 100, VD( 100 ) );
	prev = VD( 100 );
	next = VD( 100 );

	while ( scanf( "%d%d", &n, &m ) != EOF && n > 0 && m > 0 )
	{
		for ( i = 0; i < n; i++ ) for ( j = 0; j < n; j++ ) scanf( "%lf", &C[i][j] );
		printf( "%.2lf\n", solve() );
	}

	return 0;
}

C++: #include <iostream>
#include <stdio.h>
using namespace std;

int main(){
  while(1){
    int n,m; cin >> n >> m;
    if( n == 0 && m == 0 ) break;
    
    int i,j;
    double data[101][101];
    for( i = 1; i <= n; i++ ){
      for( j = 1; j <= n; j++ ){
	cin >> data[i][j];
      }
    }
    
    int tmp;
    double total,total_max = -1.0;
    for( i = 1; i <= n; i++ ){
      tmp = i;
      total = 1.0;
      while( m > 1 ){
	m--;
	double max = -1.0;
	  for( j = 1; j <= n; j++ ){
	    if( max < data[tmp][j] ){
	      max = data[tmp][j];
	      tmp = j;
	    }
	  }
	total *= max;
      }
      if( total_max < total ) total_max = total;
    }
    printf("%.2f\n",total_max);
  }
  return 0;
}

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

using namespace std;

int main()
{
	int n, m;
	long double r, a[101][101], dp[101][101];
	
	while(cin>>n>>m && (m+n)){
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				cin >> a[i][j];
			}
		}
		fill(&dp[0][0], &dp[100][100], 0);
		
		for(int i = 0; i < n; i++){
			dp[i][0] = 1.0;
		}
		
		for(int k = 1; k < m; k++){
			for(int i = 0; i < n; i++){
				for(int j = 0; j < n; j++){
					dp[i][k] = max(dp[i][k], dp[j][k-1]*a[i][j]);
				}
			}
		}
		
		r = 0.0;
		for(int j = 0; j < n; j++){
			r = max(r, dp[j][m-1]);
		}
		
		printf("%.2lf\n", r);
	}
	
	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int n, m;
double table[128][128], memo[128][128];
double maxGrow[128];

double rec(int p, int prv)
{
	if(p == m - 1) return maxGrow[prv];
	if(prv != -1 && memo[p][prv] != -1) return memo[p][prv];
	
	int sld;
	double res = -1;
	for(int i = 0; i < n; i++)
	{
		double sub = rec(p + 1, i);
		
		if(res < sub)
		{
			res = sub;
			sld = i;
		}
	}
	
	return memo[p][prv] = (prv == -1 ? 1.0 : table[prv][sld]) * res;
}

int main()
{
	int i, j;
	while(cin >> n >> m && n)
	{
		rep(i, n) rep(j, n) cin >> table[i][j];
		
		rep(i, 128) maxGrow[i] = *max_element(table[i], table[i] + 128);
		rep(i, 128) rep(j, 128) memo[i][j] = -1;
		
		printf("%.2f\n", rec(0, -1));
	}	
}