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<cstdio>
#include<algorithm>
#include<vector>
#include<cassert>
#include<cmath>
#define EPS 1e-10
using namespace std;

int m,n;
double dp[110][110];
int Just;
//vector<double> matrix[110];
double matrix[110][110];
double rec(int next,int counter){
  if(dp[next][counter] != -10)return dp[next][counter];
  if(counter  == 0){
    return 1.0;
  }
  double HANMA = 0.0,test=0.0;
  
  
  for(int i=0;i<n;i++){  
     
    //HANMA = max(HANMA,rec(i,counter-1)*matrix[next][i]);
    test = rec(i,counter-1)*matrix[next][i];
    if(test > HANMA)HANMA = test;
  } 
  
  dp[next][counter] = HANMA;
  return HANMA;
}
 
 
int main(){
   
  double In;
  
  while(cin >> n >> m && n && m){
    //for(int i=0;i<=n;i++)matrix[i].clear();
     
    for(int i=m;i>=0;i--)for(int j=0;j<n;j++)dp[j][i] = -10;
    for(int i=0;i<n;i++)dp[i][0] = dp[i][1] = 1;
  
  
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
    //cin >> matrix[i][j];
    scanf("%lf",&matrix[i][j]);
    //matrix[i].push_back(In);
      }
    }
  
 
    double ans = -1;
  
   
      for(int I=0;I<n;I++){
    Just = I;
    double tes = rec(I,m);
    ans = max(ans,dp[Just][m]);
      }
     
 
      //for(int i=1;i<=m;i++)cout << dp[0][i] << " ";
      //cout << endl;
 
    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 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<pair<double,int>>> dp(m);

        FOR(i,0,n){
            FOR(j,0,n){
                cin >> bt[i][j] ;
            }
            dp[0].push_back(pair<double,int>(1.0,i));
        }

        double ans = 0.0;
        FOR(i,0,m-1){
            FOR(j,0,n){
                FOR(k,0,dp[i].size()){
                    double g;
                    int f;
                    tie(g,f) = dp[i][k];
                    dp[i+1].push_back(pair<double,int>(g*bt[f][j],j));
                    ans = max(ans, g*bt[f][j]);
                }
            }
        }
        printf("%.2f\n",ans);
    }
    return 0;
}

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

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;
const int INF = 1 << 30;

int main()
{
	double T[128][128], dp[128][128];
	int n, m;

	while(cin >> n >> m)
	{
		if(n == 0 && m == 0)
		{
			break;
		}

		for(int i = 0; i < n; i++)
		{
			for(int j = 0; j < n; j++)
			{
				cin >> T[i][j];
			}
		}
		
		memset(dp, 0, sizeof(dp));
	
		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][k] : i回目で肥料jを使った時の最大の苗木の大きさ
					dp[i][k] = max(dp[i][k], dp[i-1][j]*T[k][j]);
				}
			}
		}

		double res = 0; 
		for(int i = 0; i < n; i++)
		{
			res = max(res, dp[n-1][i]);
		}
	
		res *= 100;
		res = int(res+0.5);
		res /= 100;

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

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

typedef long long int64;
const int inf = (int)1e9;

int main()
{
	while(true) {
		
		int n, m;
		vector<vector<double> > g;
		vector<double> dp[2];
		
		scanf("%d%d", &n, &m);
		if(n == 0)
			break;
		g.resize(n); dp[0].resize(n); dp[1].resize(n);
		for(int i = 0; i < n; ++i) {
			g[i].resize(n);
			for(int j = 0; j < n; ++j)
				scanf("%lf", &g[i][j]);
		}
		
		for(int i = 0; i < n; ++i)
			dp[0][i] = 1;
		
		for(int day = 1; day < m; ++day) {
			
			for(int i = 0; i < n; ++i) {
				
				double &val = dp[day % 2][i];
				val = 0;
				for(int j = 0; j < n; ++j)
					val = max(val, dp[(day - 1) % 2][j] * g[j][i]);
			}
		}
		
		double ans = 0;
		for(int i = 0; i < n; ++i)
			ans = max(ans, dp[(m - 1) % 2][i]);
		
		ans = round(ans * 100) / 100;
		printf("%.2lf\n", ans);
	}
	return 0;
}

/* ハラスメントに負けず */
/* 0完太陽にも負けず */
/* はやく人権を獲得したい */
/* nullmineralが書きましたが */
/* 責任はまったくとりません */

C++: 
#include<iostream>
#include<algorithm>
#include<vector>
#include<iomanip>
using namespace std;
int main()
{
  cout<<setprecision(2);
  cout<<setiosflags(ios::fixed);
  int n,m,i,j,k;
  double M;
  while(cin>>n>>m,n|m){
    vector< vector<double> >manure(n,vector<double>(n)),dp(n,vector<double>(n,1.0));
    for(i=0;i<n;i++)for(j=0;j<n;j++)cin>>manure[i][j];
    for(i=1;i<n;i++){
      for(j=0;j<n;j++){
	dp[i][j]=dp[i-1][j];
	for(k=0;k<n;k++){
	  dp[i][j]=max(dp[i][j],dp[i-1][k]*manure[k][j]);
	}
      }
    }
    M=0.0;
    for(j=0;j<n;j++)M=max(M,dp[n-1][j]);
    cout<<M<<endl;
  }
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int a,b;
  while(cin>>a>>b,a||b){
    vector<vector<double> >in(a,vector<double>(a));
    rep(i,a)rep(j,a)cin>>in[i][j];
    vector<vector<double> >out(b,vector<double>(a));
    rep(i,a)out[0][i]=1.0;
    rep(i,b-1){
      rep(j,a){
	double max1=0;
	rep(k,a)if(max1<out[i][k]*in[k][j])max1=out[i][k]*in[k][j];
	out[i+1][j]=max1;
      }
    }
    double max1=0;
    rep(i,a)if(max1<out[b-1][i])max1=out[b-1][i];
    double tmp=max1*100-(int)(max1*100);
    //printf("%.3f\n",tmp);
    if(tmp-0.50>=-ESP)max1+=0.01;
    printf("%.2f\n",max1);
  }
}