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]);
                }
            }
        }

        FOR(i,0,n)
            ans = max(ans,dp[m-1][i]);

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

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

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

int main(void){
	int n,m;
	while( cin >> n >> m,n|m){
		for(int y=0;y<n;y++)
			for(int x=0;x<m;x++)
				dp[x][y]=0;
		for(int y=0;y<n;y++)
			for(int x=0;x<n;x++)
				cin >> grow[x][y];
		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++)
				for(int k=0;k<n;k++)
				dp[i][j]=max(dp[i][j],dp[i-1][k]*grow[k][j]);
		double MAX=0;
		for(int i=0;i<n;i++)
			MAX=max(MAX,dp[m-1][i]);
		cout.precision(2);
		cout << fixed <<MAX << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
double dp[100][100];
double tk[100][100];
int main()
{
    while(1)
    {
        int n,m;
        cin>>n>>m;if(!n)return 0;
        for(int i=0;i<n;++i){
            for(int j=0;j<n;++j){
                cin>>tk[i][j];
            }
        }
        for(int i=0;i<100;++i){
            fill(dp[i],dp[i]+100,0);
        }
        for(int i=0;i<n;++i){
            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){
                    double buf;
                    buf=dp[i-1][j]*tk[j][k];
                    dp[i][k]=max(dp[i][k],buf);
                }
            }
        }
        double ans=0;
        for(int i=0;i<n;++i){
            ans=max(ans,dp[m-1][i]);
        }
        printf("%.2lf\n",ans);
    }
    return 0;
}

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

int main(){
  double dp[100][100];
  int n,m;
  double table[100][100];

  while(1){
    scanf("%d %d",&n,&m);
    if(!n && !m)break;

    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++)scanf("%lf",&table[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 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.0;
    for(int i=0;i<n;i++)ans = max(ans,dp[m-1][i]);

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

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

using namespace std;

#define ALL(co) co.begin(), co.end()
#define tpl(...) make_tuple(__VA_ARGS__)

typedef long long LL;
typedef pair<int, int> P; typedef pair<int, P> IP; typedef pair<P, P> PP;
typedef vector<int> Array; typedef vector<vector<int> > Array2;
typedef vector<LL> LArray; typedef vector<P> PArray; typedef vector<string> SArray;

const int INF = 1 << 29;
const LL LINF = 1LL << 60;

inline int getInt() { int itiv; return (cin >> itiv, itiv); }
template <typename T> void readAll(vector<T>& vec) { for (int i = 0, size = vec.size(); i < size; i++) cin >> vec[i]; }
template <typename T, typename U> void readAll(vector<pair<T, U> >& vec) { for (int i = 0, size = vec.size(); i < size; i++) cin >> vec[i].first >> vec[i].second; }
template < typename T > inline string toString( const T &a ){ ostringstream oss; oss << a; return oss.str(); };
inline bool between(int min, int max, int n) { return min <= n && n <= max; }
inline bool inRange(int begin, int end, int n) { return begin <= n && n < end; }
inline bool inRange(int size, int n) { return 0 <= n && n < size; }

int dx[] = { -1, 0, 1, 0 }, dy[] = { 0, -1, 0, 1 };
int dr[] = { 0, -1, 0, 1 }, dc[] = { -1, 0, 1, 0 };

int m, n;

int main(void)
{
	ios::sync_with_stdio(false);
	while(cin >> n >> m && n)
	{
		vector<vector<double> > table(n, vector<double>(n));
		for (int i = 0; i < n; i++)
		{
			readAll(table[i]);
		}
		
		vector<double> next(n);
		vector<double> now(n, 1);

		for (int i = 1; i < m; i++)
		{
			for (int j = 0; j < n; j++)
			{
				next[j] = now[0] * table[j][0];
				for (int k = 0; k < n; k++)
				{
					next[j] = max(next[j], now[k] * table[j][k]);
				}
			}
			now = next;
		}
		cout << (int)((*max_element(ALL(now)) + 0.005) * 100) / 100.0 << endl;
	}
	return 0;
}

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

using namespace std;

const double INF = 10000000.0;

int n, m;
double dp[100][100];
double table[100][100];

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