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 <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;

int main(){
  int n,m; 
  double data[101][101],tree[101][101];
  while ( cin >> n >> m ,n+m ) {
    for ( int i = 1; i <= n; i++ ) {
      for ( int j = 1; j <= n; j++ ) cin >> tree[i][j];
    }

    for ( int i = 1; i <= n; i++ ) {
      for ( int j = 1; j <= m; j++ ) data[i][j] = -1.0;
    }


    for ( int i = 1; i <= n; i++ ) data[i][1] = 1.0;
    
    int tmp;
    int cnt = 0;
    for( int i = 1; i <= n; i++ ) {
      cnt++;
      tmp = cnt;
      for( int j = 1; j < m; j++ ) {
	for( int k = 1; k <= n; k++ ) {
	  if ( data[i][j+1] < data[i][j] * tree[tmp][k] ) {
	    data[i][j+1] = data[i][j] * tree[tmp][k];
	    tmp = k;
	  }
	}
      }
    }
    double maxv = -1.0;
    for( int i = 1; i <= n; i++ ) maxv = max( data[i][n], maxv );

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

  }
  return 0;
}

C++: #include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

int main(){
    int n,m;
    while(cin >> n >> m,n){
        double table[105][105];
        rep(i,n){
            rep(j,n){
                cin >> table[i][j];
            }
        }

        double dp[105][105] = {{0}}; //テヲツ慊?・ツセツ古」ツ?ォテ、ツクツ偲」ツ?暗」ツ?淌ィツつ・テヲツ鳴凖」ツ??ヲツ猟・テ」ツ?ォテ」ツ?。
        rep(i,105) dp[i][0] = 1;
        range(i,1,m){
            rep(j,n){
                rep(k,n){
                    dp[j][i] = max(dp[j][i], dp[k][i - 1] * table[k][j]);
                }
            }
        }
        
        double maxi = 0;
        rep(i,n){
            maxi = max(maxi, dp[i][m - 1]);
        }
        cout <<fixed << setprecision(2) << maxi << endl;
    }
}

C++: #include <stdio.h>

double dp[100][100];

#define REP(i, n) for (int i = 0; i < (n); i++)
#define MAX(x, y) ((x) > (y) ? (x) : (y))

int main(void)
{
	double grow[100][100]; //[ツ前ツづ個氾ャツ猟ソ][ツ債。ツづ個氾ャツ猟ソ]
	int n, m;
	
	while (1){
		REP(i, 100) dp[0][i] = 1.0;
		
		scanf("%d%d", &n, &m);
		
		if (n == 0 || m == 0){
			break;
		}
		
		REP(i, n) REP(j, n) scanf("%lf", &grow[i][j]);
		
		for (int i = 1; i < m; i++){
			for (int j = 0; j < n; j++){
				dp[i][j] = dp[i - 1][0] * grow[0][j];
				for (int k = 1; k < n; k++){
					dp[i][j] = MAX(dp[i][j], dp[i - 1][k] * grow[k][j]);
				}
			}
		}
		
		double ans = 0;
		REP(i, n){
			ans = MAX(ans, dp[m - 1][i]);
		}
		
		printf("%.2lf\n", ans);
	}
	return (0);
}

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

const double inf = 1000;

int n, m;
double g[101][101];
double dp[101][101]; //i???????????????k???????????????????????§???

int main(){
	while(true){
		for(int i = 0; i < 101; ++i){
			for(int j = 0; j < 101; ++j)dp[i][j] = -1;
		}
		
		std::cin >> n >> m;
		if(n == 0 && m == 0)break;
		
		for(int i = 0; i < n; ++i){
			for(int j = 0; j < n; ++j){
				std::cin >> g[i][j];
			}
		}
		
		for(int i = 0; i < n; ++i)dp[0][i] = 1.0;
		
		for(int i = 0; i < m - 1; ++i){
			for(int j = 0; j < n; ++j){
				if(dp[i][j] == -1)continue;
				
				double maxV = -inf;
				int maxI;
				for(int k = 0; k < n; ++k){
					int v = dp[i][j] * g[j][k];
					if(v > maxV)maxV = v, maxI = k;
				}
				
				dp[i + 1][maxI] = maxV;
			}
		}
		
		
		double ans = 0;
		for(int i = 0; i < n; ++i){
			if(dp[m - 1][i] > ans)ans = dp[m - 1][i];
		}
		
		printf("%.2f\n", ans);
	}
	
	return 0;
}

C++: #define _USE_MATH_DEFINES
#define INF 10000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int,string> P;

static const double eps = 1e-8;

double dp[101][101];
double table[100][100];

int main(){

	int n,m;
	while(~scanf("%d %d",&n,&m)){
		if(n==m && m==0) break;
		for(int y=0;y<n;y++){
			for(int x=0;x<n;x++){
				scanf("%lf",&table[y][x]);
			}
		}

		fill((double*)dp,(double*)dp+101*101,1.0);

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

		printf("%.2lf\n",floor(dp[n-1][m-1]+0.005+eps));
	}
}

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 <= n; i++){
            ans = max(dp[m][i], ans);
        }
        printf("%.2f\n", ans);
    }


    return 0;
}

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

int main(){
  int N,M;
  while(cin>>N>>M,N||M){
    long double t[100][100];
    long double dp[M][N];

    for(int i=0;i<N;i++){
      for(int j=0;j<N;j++){
	scanf("%Lf",&t[i][j]);
      }
    }

    for(int i=0;i<M;i++){
      for(int j=0; j<N;j++){
	dp[i][j]=0;
      }
    }
    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]*t[k][j]);
	}
      }
    }
    long double ans=0;

    for(int i=0;i<N;i++) ans=max(ans,dp[M-1][i]);

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