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 <iostream>
#include <stdio.h>
#include <vector>
#include <cmath>

using namespace std;

void solve()
{
	int n, m;
	while(cin >> n >> m, n || m)
	{
		vector< vector<long double> > dp(m, vector<long double>(n, 1.0));
		vector< vector<long double> > data(n, vector<long double>(n));
		for(int i = 0; i < n; ++i)
		{
			for(int j = 0; j < n; ++j)
			{
				cin >> data[i][j];
			}
		}
		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] * data[k][j]);
				}
			}
		}
		long double maximum = 0;
		for(int i = 0; i < n; ++i)
		{
			maximum = max(maximum, dp[m - 1][i]);
		}
		printf("%.2lf\n", maximum);
	}
}

int main()
{
	solve();
	return(0);
}

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

const int MAX_N = 100, MAX_M = 100;
const double EPS = 1e-10;

int n,m;
double g[MAX_N][MAX_N];
double dp[MAX_M][MAX_N]; //dp[cnt][prev]

double rec(int cnt, int prev)
{

    if(cnt == 0)
        return dp[0][prev] = 1.0;

    if(dp[cnt][prev] > 0.0)
        return dp[cnt][prev];
    
    double tmp, ret = 0.0;
    for(int i = 0; i < n; i++) {
        tmp = rec(cnt - 1, i) * g[prev][i];
        if(ret < tmp) 
            ret = tmp;
    }

    return dp[cnt][prev] = ret;
}

int 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 i = 0; i < m; i++) 
            for(int j = 0; j < n; j++) 
                scanf("%lf", &g[i][j]);

        double ans = 0.0, tmp;
        for(int i = 0; i < n; i++) {
            tmp = rec(m - 1, i);
            if(ans < tmp)
                ans = tmp;
        }

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

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <climits>
#include <stdio.h>

using namespace std;

typedef vector < double > VI;
typedef vector < VI > VVI;

int main () {
	int n, m;

	while ( true ) {
		cin >> n >> m;

		if ( !n && !m ) {
			break;
		}

		VVI g(n + 4, VI(n + 4, 0));
		VVI dp(n + 4, VI(m + 4, 0));

		for(int i = 1; i <= n; i++) {
			for(int j = 1; j <= n; j++) {
				cin >> g[i][j];
			}
		}

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

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

		double ans = 0;

		for(int i = 0; i <= n; i++) {
			ans = max(ans, dp[n - 1][i]);
		}

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

C++: #include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

double table[100][100];


int main(){
	int n, m ;
	while(cin >> n >> m , n){
		rep(i,n)rep(j,n)cin >> table[i][j];
		
		long double dp[100][100] = {{0.0}};
		
		rep(i,n)dp[0][i] = 1.0;
		
		rep(i,m-1){ // kaisu 
			rep(j,n){ // chokuzen 
				rep(k,n){ // current
					dp[i+1][k] = max(dp[i+1][k] , dp[i][j] * table[j][k]);
				}
			}
		}
		long double ret = 0;
		rep(i,n){
			ret = max(ret,dp[m-1][i]);
		}
		//long long out = (ret * 100.0);
		//printf("%.2Lf\n",out/100.0);
		printf("%.2Lf\n",ret);
	}
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cassert>
#include<cmath>
#define EPS 1e-10
using namespace std;
typedef pair<double,int> P;
int m,n;
double total;
double dp[110][110];
int Just;
//vector<double> matrix[110];
double matrix[110][110];
double rec(int next,int counter){
  if(dp[next][counter] > 0)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[Just][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];
	//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 <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){

	double table[101][101];

	int n,m;
	const int INF=100000000;
	while(cin>>n>>m&&!(n==0&&m==0)){
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++)
				cin>>table[i][j];
		}
		double dp[2][101];
		fill(dp[0],dp[0]+101,1);
		fill(dp[1],dp[1]+101,0);

		double *prv=dp[0];
		double *nxt=dp[1];
		for(int k = 0; k < m-1; k++){
			for(int i = 0; i < n; i++){
				for(int j = 0; j < n; j++){
					nxt[i]=max(nxt[i],prv[j]*table[j][i]);
				}
			}
			swap(prv,nxt);
			fill(nxt,nxt+101,0);
		}

		double maxNum=0;
		for(int i = 0; i < n; i++){
			maxNum=max(maxNum,prv[i]);
		}
		double ret = ((double)((int)(maxNum*100+0.5)))/100;
		printf("%.2f\n",ret);
	}

	return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#define ll long long int
#define ld long long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> P;

string str;

int main()
{
  int n,m;
  int i,j,k;
  double dp[105][105];
  double grow[105][105];
  int maxi[105];//??????????????§???????????¨????????´????????\???

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

    rep(i,n)rep(j,n)
      cin>>grow[i][j];

    double temp;
    int tempi;
    rep(j,n){
      temp=0;
      rep(i,n)
        if(temp<grow[i][j]){
	  temp=grow[i][j];
	  tempi=i;
	}
      maxi[j]=tempi;
    }

    rep(j,n)
      dp[0][j]=1.0;

    for(i=1;i<m;i++)
      for(j=0;j<n;j++){
	temp=0;
	rep(k,n)
	  temp=max(temp,dp[i-1][k]*grow[k][j]);
	dp[i][j]=temp;
      }
      
    double sum=0;

    rep(j,n)
      sum=max(sum,dp[n-1][j]);
 
    printf("%.2f\n",sum);
  }

}