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++: //43
#include<iostream>
#include<algorithm>
#include<iomanip>

using namespace std;

int main(){
  for(int n,m;cin>>n>>m,n|m;){
    double g[100][100]={{}};
    for(int y=0;y<n;y++){
      for(int x=0;x<n;x++){
	cin>>g[y][x];
      }
    }
    double r[101][100]={{}};
    fill(r[0],r[1],1);
    for(int i=0;i<m-1;i++){
      for(int j=0;j<n;j++){
	for(int k=0;k<n;k++){
	  r[i+1][j]=max(r[i+1][j],r[i][k]*g[k][j]);
	}
      }
    }
    cout<<fixed<<setprecision(2)<<*max_element(r[m-1],r[m])<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<cmath>
#include<vector>

using namespace std;

const double eps = 1.0e-10;
double eq(double a, double b){ //a==b
  return abs(b-a)<eps;
}
double gt(double a, double b){ //a>b
  return !eq(a,b) && a > b;
}

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];
      }
    }
    vector<int> colors;
    vector<double> greedy;
    for(int i = 0; i < n; ++i){
      colors.push_back( i );
      greedy.push_back( 1.0 );
    }

    for(int k = 0; k < m-1; ++k){
      vector<int> next_colors;
      vector<double> next_greedy;
      for(int i = 0; i < colors.size(); ++i){
	double maximum = -1;
	for(int j = 0; j < n; ++j){
	  double t = greedy[i] * table[ colors[i] ][ j ];
	  if( gt( t, maximum ) ){
	    maximum = t;
	  }
	}
	for(int j = 0; j < n; ++j){
	  double t = greedy[i] * table[ colors[i] ][ j ];
	  if( eq( t, maximum ) ){
	    next_colors.push_back( j );
	    next_greedy.push_back( t );
	  }
	}
      }
      colors.clear();
      greedy.clear();
      for(int i = 0; i < next_colors.size(); ++i){
	colors.push_back( next_colors[i] );
	greedy.push_back( next_greedy[i] );
      }
    }
    
    for(int i = 0; i < greedy.size(); ++i){
      if( gt( greedy[i], answer ) )
	answer = greedy[i];
    }
    printf("%.2lf\n",answer);

  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

int main(){
  int n, m;
  double g[100][100];
  double dp[101][100]; //dp[i][j]:i番目までで前に肥料jを与えたときの最大の苗木長

  while(scanf("%d %d", &n, &m), n){
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        scanf("%lf", &g[i][j]);
      }
    }

    fill_n( *dp, 101 * 100, -1);

    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++){
        if(dp[i][j] == -1) continue;
        for(int k = 0; k < n; k++){
          dp[i + 1][k] = max( dp[i + 1][k], dp[i][j] * g[j][k]);
        }
      }
    }

    int ret = 0;
    for(int i = 1; i < n; i++){
      if(dp[m][i] > ret) ret = i;
    }
    printf("%.2lf\n", dp[m][ret]);
  }
  return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<utility>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<set>
 
using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+9
#define EPS 1e-9
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = j; i < (k); i++)
typedef long long ll;
double fert[128][128];
double dp[128][128];
int main(){
    int n,m;
    while(scanf("%d%d",&n,&m),(n|m)){
        memset(dp,0,sizeof(dp));
        rep(i,n)rep(j,n)scanf("%lf",&fert[i][j]);
        rep(i,m){
            rep(j,n){
                if(i == 0)dp[i][j] = 1.0;
                else{
                    rep(k,n){
                        dp[i][j] = max(dp[i][j],dp[i-1][k] * fert[k][j]);                    
                    }
                }
            }
        }
        double res = -1.0;
        rep(i,n){
            res = max(res,dp[m-1][i]);
        }  
        printf("%.2lf\n",res);
    }
    return 0;
}

C++: #include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>
 
int n, m;
double grow[100][100];
double dp[110][110];
 
int main() {
    while(std::cin >> n >> m, n + m) {
     
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            std::cin >> grow[i][j];
        }
    }
 
    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) {
            dp[i][j] = 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] = std::max(dp[i][j], dp[i - 1][k] * grow[k][j]);
            }
        }
    }
 
    printf("%.2f\n", ((int)(*std::max_element(dp[m - 1], dp[m - 1] + n) * 100 + 0.5)) / 100.);
 
 
    }
}

C++: #include<iostream>
#include<algorithm>
#include<ios>
using namespace std;
int n,m;
double dp[101][100];
double g[100][100];
main()
{
	while(cin>>n>>m,n)
	{
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)cin>>g[i][j];
			for(int j=0;j<=m;j++)dp[j][i]=1;
		}
		for(int i=0;i<m-1;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]*g[k][j]);
				}
			}
		}
		double ans=1;
		for(int i=0;i<n;i++)ans=max(ans,dp[m-1][i]);
		printf("%.02f\n",ans);
	}
}