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 <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
int n, m; double e[111][111], dp[111][111];
int main() {
	while (cin >> n >> m) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) cin >> e[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 k = 0; k < n; k++) {
					dp[i][j] = max(dp[i][j], dp[i - 1][k] * e[k][j]);
				}
			}
		}
		cout << fixed << setprecision(2) << *max_element(dp[m - 1], dp[m - 1] + n) << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<math.h>
#include<stdio.h>
using namespace std;

int main(void){
	double dp[100][100];	// [回数][種類]
	double table[100][100];
	int N, T;

	while(true){
		cin >> T >> N;
		if( T == 0 && N == 0)
			break;
		for(int bef=0; bef<T; bef++)
			for(int cur=0; cur<T; cur++)
				cin >> table[bef][cur];

		// init
		for(int n=0; n<N; n++)
			for(int t=0; t<T; t++)
				dp[n][t] = n == 0 ? 1 : 0;
		
		// calc
		for(int n=1; n<N-1; n++){
			for(int tcur=0; tcur<T; tcur++){
				for(int taft=0; taft<T; taft++){
					dp[n+1][taft] = max(dp[n+1][taft], dp[n][tcur]*table[tcur][taft]);
				}
			}
		}

		// out calc
		double res = 0;
		for(int t=0; t<T; t++)
			res = max(dp[N-1][t], res);

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

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

int main() {
  double f[101][101];
  double dp[101][101];
  int n,m;
  while (cin >> n >> m,n||m) {
    
    for ( int i = 0; i < n; i++ ) {
      for ( int j = 0; j < n; j++ ) {
	cin >> f[i][j];
      }
    }

    for ( int i = 0; i < m; i++ ) {
      for ( int j = 0; j < n; j++ ) {
	dp[i][j] = 0.0;
      }
    }

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

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

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

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

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,b,n) for(int i=b;i<n;i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int n,m;
const int MAX_N =120;
const int MAX_M =120;
double dp[MAX_N][MAX_M];//dp[i][j]:=直前にjを与え、i回目に肥料を与えたときの最大の成長
double memo[MAX_N][MAX_N];
int main(){
	while(1){
		cin>>n>>m;
		if(n==0&&m==0){
			break;
		}
		for(int i =0;i <MAX_N;i++){
			for(int j =0;j <MAX_N;j++){
				dp[i][j] =0;
				memo[i][j]=0;
			}
		}
		rep(i,n){
			rep(j,n){
				cin>>memo[i][j];
			}
		}
		bool flag =false;
		if(m==1){
			printf("%.2f\n",1.00);
			continue;
		}

		rep(i,n)dp[1][i] =1;

		double ans =0;
		for(int i =1;i <m;i++){
			for(int j =0;j <n;j++){//直後
				for(int k =0;k <n;k++){//直前
					dp[i+1][j] =max(dp[i+1][j],dp[i][k]*memo[k][j]);
					if(dp[i+1][j]>ans){
						ans =dp[i+1][j];
					}
				}
			}
		}
		ans +=0.005;
		ans =ans*100;
		ans =(int)ans;
		ans =(double)ans/100;
		printf("%.2f\n",m==1?1:ans);
	}
	return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
using namespace std;
double dp[100][100],g[100][100];
int main(){
  int n, m;
  while(cin >> n >> m , n){
    for(int i = 0 ; i < n ; i ++ ){
      for(int j = 0 ; j < n ; j++ ){
        cin >> g[i][j];
      }
    }
    fill_n( dp[0], n, 1.0);
    for(int i = 1 ; i < m ; i++ ) for(int j = 0 ; j < n ; j++ ) dp[i][j] = 0;
    for(int i = 1 ; i < m ; i++ ){ //回数
      for(int prev = 0 ; prev < n ; prev++ ){ // prev
        for(int now = 0 ; now < n ; now++ ){ // now
          dp[i][now] = max( dp[i][now], dp[i - 1][prev] * g[prev][now]);
        }
      }
    }
    cout << fixed << setprecision(2) << *max_element( dp[m - 1], dp[m - 1] + n ) << endl;
  }
}

C++: import java.util.Scanner;
import java.math.BigDecimal;
public class Main {
	void doIt() {
		Scanner stdIn = new Scanner(System.in);
		while(true) {
			int n = stdIn.nextInt();//肥料の種類
			int m = stdIn.nextInt();//肥料を与える回数
			if(n + m == 0) break;

			double[][] table = new double[n][n];
			for(int r = 0; r < n; r++) {
				for(int c = 0; c < n; c++) {
					table[r][c] = stdIn.nextDouble();
				}
			}
			double[][] dp = new double[m][n];
			for(int r = 0; r < dp[0].length; r++) {
				dp[0][r] = 1;
			}
			for(int k = 1; k < m; k++) {
				for(int r = 0; r < n; r++) {
					for(int c = 0; c < m; c++) {
						dp[k][c] = Math.max(dp[k][c], dp[k - 1][r] * table[r][c]);
					}
				}
			}
			double ans = -1;
			for(int r = 0; r < dp[dp.length - 1].length; r++) {
				ans = Math.max(ans, dp[dp.length - 1][r]);
			}
			BigDecimal answer = new BigDecimal(String.valueOf(ans));
			ans = answer.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
			System.out.printf("%1.2f\n", ans);
		}

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Main().doIt();
	}

}

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

using namespace std;

int main(){
  int n,m;
  double In;
 
  while(cin >> n >> m && n && m){
    vector<double> matrix[n];
    double mex = 0,sam[n];
    for(int i=0;i<n;i++)sam[i] = -1;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	cin >> In;
	matrix[i].push_back(In);
	sam[j] = max(sam[j],In);
      }
    }

    mex = 1;
    for(int i=0;i<m-1;i++)mex*=sam[i];
    
    printf("%.2f\n",mex);


  }
  return 0;
}