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

using namespace std;

int n, m;
double in[100][100], dp[101][101];

int main( void )
{
	while(cin >> n >> m, n | m) {

		for(int i=0; i < n; ++i)
			for(int j=0; j < n; ++j) {
				cin >> in[i][j];
			}
		for(int i=1; i <= m; ++i)
			fill(dp[i], dp[i]+n, 0);
		fill(dp[0], dp[0]+n, 1);

		for(int i=1; i < m; ++i)
		{
			for(int j=0; j < n; ++j)
			{
				for(int k=0; k < n; ++k)
				{
					//printf("(%lf, %lf, %lf) = (%lf, %lf)\n", i, j, k, dp[i][j], in[j][k]*dp[i-1][j]);
					dp[i][k] = max(dp[i][k], in[j][k] * dp[i-1][j]);
					//dp[i][j] = max(dp[i][j], in[k][j] * dp[i-1][j]);
				}
			}
		}
		double Max = -1.0;
		for(int i=0; i < n; ++i) {
			Max = max(Max, dp[m-1][i]);
		}
		//for(int i=0; i < m; ++i,printf("\n"))
		//	for(int j=0; j < n; ++j) printf("%.2lf ", dp[i][j]);
		
		printf("%.2lf\n", Max);
	}
	return 0;
}

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

using namespace std;
int n, m;
double cal(double g[][110]) {
  int i, j, k;
  double dp[110][110] = {};
  double all_MAX = 0.0;
  
  for(i = 1; i <= n; i++) {
    dp[1][i] = 1.0;
  }
  
  for(i = 2; i <= m; i++)
    for(j = 1; j <= n; j++) {
      dp[i][j] = 0.0;
      for(k = 1; k <= n; k++) {
	dp[i][j] = 1.0 * max(dp[i-1][k]*g[k][j], dp[i][j]);
      }
    }
  
    for(j = 1; j <= n; j++) {
      //     cout << dp[i][j] << ' ';
      all_MAX = max(dp[m][j], all_MAX);
    //     cout << endl;
  }
  
  return all_MAX;
}

	  
int main() {
  int i, j;
  while(cin >> n >> m, n != 0 || m != 0) {
    double g[110][110] = {};
    
    for(i = 1; i <= n; i++)
      for(j = 1; j <= n; j++)
	cin >> g[i][j];
    printf("%.2lf\n", cal(g));
  }
  
  return 0;
}

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

double c[100][100];
double dp[100][100];//i??\??????j???????????¬
signed main() {
	int a, b;
	while(scanf("%d%d", &a, &b),a|b) {
		for (int d = 0; d < a; d++) {
			for (int e = 0; e < a; e++) {
				scanf("%lf", &c[d][e]);
			}
		}
		memset(dp, 0, sizeof(dp));
		for (int d = 0; d < a; d++)dp[0][d] = 1;
		for (int d = 1; d < b; d++) {
			for (int e = 0; e < a; e++) {//????????\
				for (int f = 0; f < a; f++) {//????????\
					dp[d][e] = max(dp[d][e], dp[d - 1][f] * c[f][e]);
				}
			}
		}
		double MAX = 0;
		for (int d = 0; d < a; d++) {
			MAX = max(MAX, dp[b - 1][d]);
		}
		printf("%.10lf\n", MAX);
	}
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#include <ctime>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1 << 27;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)

double grow[100][100];
double dp[101][101];

int main(){
	int n, m;
	while(cin >> n >> m && (n || m)){
		fill(&dp[0][0], &dp[100][100] + 1, 0.0);
		rep(i, n)rep(j, n)cin >> grow[i][j];
		m--;
		rep(i, n) dp[0][i] = 1.0;
		rep(i, m){
			rep(j, n){
				rep(k, n){
					dp[i+1][j] = max(dp[i+1][j], dp[i][k] * grow[k][j]);
				}
			}
		}
		double res = 0.0;
		rep(i, n) res = max(res, dp[m][i]);
		cout << fixed << setprecision(2) << res << endl;
	}
}

C++: #include <iostream>
#include <cstring>	// require memset
#include <cstdio>	// require printf
//#include <fstream>	// require freopen

using namespace std;

const double max_g = 10000.0;
double t[100][100];

bool v[100];

double dfs (int n, int m, int depth, int from, double s )
{
	double res = 0.0;

	if (depth == m ){
		return s;
	} // end if

	for (int i = 0; i < n; ++i ){
		if (!v[i] ){
			v[i] = true;
			s *= t[from][i];
			res = dfs (n, m, depth + 1, i, s );
		} // end if
	} // end for

	return res;
}

		 
double search (int n, int m )
{
	int i,j;
	double res = 0.;

	for (i = 0; i < n; ++i ){
		//vector <bool> v (n, false );
		memset (v, false, sizeof(v ) );
		res = max (res, dfs (n, m, 0, i, 1. ) );
 	} // end for

	return res;
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.babytree", "r", stdin );
	int n, m;	// ì¿Ì, ì¿ð^¦éñ

	while (cin >> n >> m && n && m ){
		memset (t, 0., sizeof(t ) );
		for (int from = 0; from < n; ++from ){
			for (int to = 0; to < n; ++to ){
				cin >> t[from][to];
			} // end for
		} // end for
		double res = search (n, m );
		res += 0.005;
		int r = (res * 100.);
		res = (double)r/100.;
		printf ( "%.2f\n", res );	
	} // end loop
		
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main() {
    return 0;
}

C++: #include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int n,m;
    double g[100][100],dp[100][100];
    while(scanf("%d%d",&n,&m),n||m){
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++)
                scanf("%lf",&g[i][j]);

            dp[0][i]=1.0;
        }
        for(int i=1;i<m;i++){
            for(int j=0;j<n;j++){
                double Max=0.0;
                for(int k=0;k<n;k++)
                    Max=max(Max,dp[i-1][k]*g[k][j]);

                dp[i][j]=Max;
            }
        }
        double Max=0.0;
        for(int i=0;i<n;i++)
            Max=max(Max,dp[m-1][i]);

        printf("%.2f\n",Max);
    }
    return 0;
}