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 <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define INF 1e9

int main(){
    while(true){
        int n,m;
        cin >> n >> m ;
        if(n==0 && m ==0)
            break;
        vector<vector<double>> bt(n,vector<double>(n));
        vector<vector<double>> dp(m,vector<double>(n,0.0));

        FOR(i,0,n){
            FOR(j,0,n){
                cin >> bt[i][j] ;
            }
            dp[0][i] = 1.0;
        }
        double ans = 0;
        FOR(i,0,m-1){
            FOR(j,0,n){
                FOR(k,0,n){
                    dp[i+1][j] = max(dp[i+1][j], dp[i][k] * bt[k][j]);
                    if(i==m-2)
                        ans = max(ans, dp[i+1][j]);
                }
            }
        }

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

C++: #include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int main(){
    int n,m;
    while(cin>>n>>m){
        if(n==0&&m==0)break;
        
        double data[110][100];
        rep(i,n){
            rep(j,n){
                cin>>data[i][j];
            }
        }
        
        double dp[200][200];
        rep(i,200)rep(j,200)dp[i][j]=0;
        
        rep(i,n)dp[0][i]=1;
        
        for(int i=1;i<m;i++){
            rep(j,n){
                rep(k,n){
                    dp[i][j]=max( dp[i][j] , dp[i-1][k]*data[k][j] );
                }
            }
        }
        
        double ans = 0;
        rep(i,n){
            ans = max( ans , dp[m-1][i] );
        }
        printf("%.2lf\n",ans);
    }
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define rep(i,x) for(int i=0;i<(x);++i)
#define rep1(i,x) for(int i=1;i<=(x);++i)
#define rrep(i,x) for(int i=(x)-1;i>=0;--i)
#define rrep1(i,x) for(int i=(x);i>=1;--i)
#define FOR(i,a,x) for(int i=(a);i<(x);++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T get(){T a;cin>>a;return a;}
template<typename T>T rev(T a){reverse(all(a));return a;}
template<typename T>istream&operator>>(istream&is,vector<T>&vec){rep(i,vec.size())is>>vec[i];return is;}
template<typename T>vector<T>&sort(vector<T>&a){sort(all(a));return a;}

const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;

double table[100][100];

double dp[100][100]; // dp[times][cur]

signed main()
{
    omajinai;

	int N, M;
	
	while (cin >> N >> M, N || M) {
		memset(dp, 0, sizeof(dp));

		rep(i, N) rep(j, N) cin >> table[i][j];

		rep(i, N) 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] * table[k][j]);
                }
			}
		}

        double ans = 0;

        rep(i, N) ans = max(ans, dp[M - 1][i]);

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

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

using namespace std;

int main(){
  int n, m, i, j, k;

  while(cin >> n >> m && n != 0 || m != 0) {
    
    double gl[101][101] = {};
    double dp[101][101] = {};
    
    for(i = 0; i < n; i++) {
      for(j = 0; j < n; j++) {
	cin >> gl[i][j];
      }
    }

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

    for(i = 1; i < m; i++) {
      for(j = 0; j < n; j++) {
	for(k = 0; k < n; k++) {
	  dp[i][j] = max(dp[i - 1][k] * gl[k][j], dp[i][j]);
	}
      }
    }

    double ans = 0.0;
    
    for(i = 0; i < n; i++) {
      ans = max(dp[m-1][i], ans);
    }
    
    printf("%.2f\n", ans);
 
  }

  return 0;

}

C++: #include <algorithm>
#include <map>
#include <vector>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define IREP(it,array) for(vector<int>::iterator it=array.begin(); it!=array.end(); ++it)
#define PREP(it,array) for(vector<P>::iterator it=array.begin(); it!=array.end(); ++it)
#define SREP(it,array) for(vector<string>::iterator it=array.begin(); it!=array.end(); ++it)

#define MP       make_pair
#define PB       push_back
#define ALL(x)   (x).begin(),(x).end()

const int INF = 1<<29;
const double EPS = 1e-9;
double zero(double d){
  return d < EPS ? 0.0 : d;
}

typedef long long LL;
typedef pair<int,int> P;


int n,m;
double g[100+1][100+1];
double memo[100+1][100+1];

double solve( int day, int prev ){
  if( day == m+1 )
    return 1.0;

  if( memo[day][prev] != 0.0 )
    return memo[day][prev];

  double res = 1.0;
  for(int i=1; i<=n; i++){
    res = max( res, solve(day+1, i) * g[prev][i] );
  }

  memo[day][prev] = res;
  return res;
}


int main()
{
  cout.setf(ios::fixed, ios::floatfield);
  cout.precision(2);

  while( cin>>n>>m, n ){
    memset( memo, 0, sizeof(memo) );

    REP(i,n+1){
      REP(j,n+1)
	g[i][j] = 1.0;
    }
    REP(i,n){
      REP(j,n){
	double t;
	cin >> t;
	g[i+1][j+1] = t;
      }
    }

    double res = solve( 1, 0 );
    res *= 100;
    res += 0.5;
    res = int(res);
    res /= 100;

    cout << res << endl;
  }


  return 0;
}