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 <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>

using namespace std;

const double Eps = 1e-8;

int main()
{
	int n, m;
	while (scanf("%d %d", &n, &m), n | m)
	{
		double g[100][100];
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < n; ++j)
				scanf("%lf", &g[i][j]);
		double rates[2][100];
		for (int i = 0; i < n; ++i)
			rates[0][i] = 1;

		for (int c = 1; c < m; ++c)
		{
			for (int i = 0; i < n; ++i)
			{
				rates[c & 1][i] = -1;
				for (int j = 0; j < n; ++j)
					rates[c & 1][i] = max(rates[c & 1][i], rates[(c+1) & 1][j] * g[j][i]);
			}
		}
		double ans = -1;
		for (int i = 0; i < n; ++i)
			ans = max(ans, rates[(m+1) & 1][i]);
		printf("%.2f\n", ans);
	}

	return 0;
}

C++: #include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int n, m;
    double h[105][105], dp[105][105] = {0};
    rep(i,105){
        dp[0][i] = 1.0;
    }
    while(cin >> n >> m, n||m){
        double ans = 0;
        rep(i,105){
            rep(j,105){
                dp[i][j] = 0;
            }
        }
        rep(i,105){
            dp[1][i] = 1;
        }
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= n; j++){
                cin >> h[i][j];
            }
        }
        for(int i = 2; i <= m; i++){
            for(int j = 1; j <= n; j++){
                for(int k = 1; k <= n; k++){
                    dp[i][j] = max(dp[i][j], dp[i - 1][k] * h[k][j]);
                }
            }
        }
        for(int i = 1; i <= m; i++){
            ans = max(dp[m][i], ans);
        }
        printf("%.2f\n", ans);
    }


    return 0;
}

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

using namespace std;

typedef unsigned long long ull;

#define pb push_back
#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

int main(){
    int n, m;
    while(cin >> n >> m, n+m){
        vector<vector<double> > v;
        rep(i, n){
            vector<double> d; double p;
            rep(j, n){cin >> p; d.pb(p);}
            v.pb(d);
        }

        double dp[110][110];
        memset(dp, 0, sizeof(dp));
        rep(i, n) dp[0][i] = 1;
        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]*v[k][j]);
                }
            }
        }
        printf("%.2f\n",max(dp[m-1][0], max(dp[m-1][1], dp[m-1][2])));
    }
}

C++: #include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define MAX 101

int main(){
  double dp[MAX][MAX],nae[MAX][MAX];
  int n,m;
  
  while(cin >> n >> m, n+m){
    rep(i,n) rep(j,n) cin >> nae[i][j]; 
    fill(dp[0],dp[MAX-1],1.0);
    
    rep(i,m) rep(j,n) rep(k,n)
      dp[i][j] = max(dp[i][j],dp[i-1][k]*nae[k][j]);

    double ans = 0;
    rep(i,n) rep(j,n)
      ans = max(ans,dp[i][j]);

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

  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<iomanip>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
#define N 110
#define M 110
double dp[M][N];
double g[M][M];
int n,m;

double shishagonyu2(double x){
  int a=x*1000;
  a=a/10+(a%10>=5?1:0);
  x=(double)a/100.0;
  return x;
}

int main(){
  //cout<<shishagonyu2(5.5555)<<endl;
  while(cin>>n>>m&&n+m){
    lol(i,n)lol(j,n)cin>>g[i][j];
    lol(i,n)dp[0][i]=1.0;
    lol(i,m)lol(j,n)dp[i+1][j]=0.0;
    lol(i,m){
      lol(j,n){
	lol(k,n){
	  dp[i+1][k]=max(dp[i+1][k],dp[i][j]*g[j][k]);
	}
      }
    }
    double ans=0;
    lol(i,n)ans=max(ans,dp[m-1][i]);
    ans=shishagonyu2(ans);
    cout<<fixed<<setprecision(2)<<ans<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

double tbl[102][102];	// ツ行ツづ個値ツづ債前ツ嘉アツ与ツつヲツつスツ氾ャツ猟ソ,ツ療アツづ個値ツづ債債。ツ嘉アツ与ツつヲツつスツ氾ャツ猟ソ

int main()
{
	int n, m;

	while (cin >> n >> m && n && m ){
		memset (tbl, 0.0, sizeof (tbl ) );
		rep (i, n ){
			rep (j, n ){
				cin >> tbl[i][j];
			} // end rep
		} // end rep
		double res = 1.0;
		rep (i, n ){	// ツ催渉可づ可選ツづ板氾ャツ猟ソ
			double curr = 1.0;
			int pre = i, next = -1;
			for (int j = 1; j < m; j++ ){
				double t = 0.0;
				rep (k, n ){
					if (t < tbl[pre][k]*curr ){
						t = tbl[pre][k]*curr;
						next = k;
					} // end if
				} // end rep
				pre = next;
				curr = t;
			} // end rep
			res = max (res, curr );
		} // end rep
		printf ("%.02lf\n", res );
	} // end while

	return 0;
}

C++: #include<iostream>
using namespace std;
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];
      }
    }
    int greed_color[n];
    double greed[n];
    for(int i = 0; i < n; ++i){
      greed_color[ i ] = i;
      greed[i] = 1.0;
    }
    for(int k = 0; k < m-1; ++k){
      for(int i = 0; i < n; ++i){
	int next_color = -1;
	double maximum = -1;
	for(int j = 0; j < n; ++j){
	  double t = greed[i] * table[ greed_color[i] ][ j ];
	  if( maximum < t ){
	    maximum = t;
	    next_color = j;
	  }
	}
	greed[i] = maximum;
	greed_color[i] = next_color;
      }
    }
    
    for(int i = 0; i < n; ++i){
      answer = max( answer , greed[i] );
    }
    printf("%.2lf\n",answer);

  }
  return 0;
}