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>
using namespace std;

int main()
{
  for(;;){
    int n,m;
    cin >> n >> m;
    if(n==0){return 0;}
    double map[n][n];
 
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	cin >> map[i][j];
      }
    }
  
    double dp[m][n];

   
  
    for(int i=0;i<m;i++){for(int j=0;j<n;j++){dp[i][j]=-1.0;}}
    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++){
	for(int k=0;k<n;k++){\
	  dp[i+1][k]=max(dp[i+1][k],dp[i][k]*map[j][i]);
	}
      }
    }
  
    for(int i=0;i<m;i++){
      for(int j=0;j<n;j++){
	//cout << dp[i][j] << " ";
      }
      //cout << endl;
    }

    double max1=-1.0;
    for(int i=0;i<n;i++){
      max1=max(max1,dp[m-1][i]);
    }
    //printf("%f",max1);
    printf("%2f\n",max1);
  }
}

C++: # include <iostream>
# include <algorithm>
# include <iomanip>

const int MAX_N = 100;
const int MAX_M = 100;

int n, m;
double dp[MAX_N][MAX_M];

double board[MAX_M][MAX_M];

int main() {
	while (1) {
		std::cin >> m >> n;
		if (n == 0 && m == 0)
			break;
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < m; ++j)
				dp[i][j] = 0;
		for (int i = 0; i < m; ++i) {
			for (int j = 0; j < m; ++j)
				std::cin >> board[i][j];
		}
		std::fill(dp[0], dp[0] + m, 1.0);
		for (int i = 1; i < n; ++i) {
			for (int j = 0; j < m; ++j) {
				for (int k = 0; k < m; ++k) {
					dp[i][j] = std::max(dp[i][j], dp[i - 1][k] * board[k][j]);
				}
			}
		}
		double res = 0;
		for (int i = 0; i < m; ++i)
			res = std::max(res, dp[n - 1][i]);
		std::cout << std::fixed << std::setprecision(2) << res << std::endl;
	}
	return 0;
}

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];
		
		double dp[100][100] = {{0}};
		
		rep(i,n)dp[0][i] = 1.0;
		
		rep(i,m-1){
			rep(j,n){
				rep(k,n){
					dp[i+1][j] = max(dp[i+1][j] , dp[i][j] * table[j][k]);
				}
			}
		}
		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);
	}
	
}

C++: #include<iostream>
using namespace std;
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];
      }
    }
    int greed_color[n];
    double greed[n];
    for(int i = 0; i < n; ++i){
      greed_color[ i ] = i;
      greed[i] = 1.0;
    }
    for(int k = 0; k < m-1; ++k){
      for(int i = 0; i < n; ++i){
	int next_color = -1;
	double maximum = greed[i];
	for(int j = 0; j < n; ++j){
	  double t = greed[i] * table[ greed_color[i] ][ j ];
	  if( maximum < t ){
	    maximum = t;
	    next_color = j;
	  }
	}
	greed[i] = maximum;
	greed_color[i] = next_color;
      }
    }
    
    for(int i = 0; i < n; ++i){
      answer = max( answer , greed[i] );
    }
    printf("%.2lf\n",answer);

  }
  return 0;
}

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

using namespace std;


int main() {
  
  int N, M;
  
  while(cin >> N >> M && (N|M)) {
    vector<vector<double> > p(N, vector<double>(N, 0));
      
    for(int i=0; i<N; i++) for(int j=0; j<N; j++) cin >> p[i][j];
      
    vector<vector<double> > dp(M, vector<double>(N, 0));
    for(int i=0; i<N; i++) dp[0][i] = 1.0;
	
    for(int k=1; k<M; k++)
      for(int i=0; i<N; i++)
	for(int j=0; j<N; j++)
	  dp[k][i] = max(dp[k][i], dp[k-1][j]*p[j][i]);
    
    double res = 0.0;
    for(int i=0; i<N; i++) res = max(res, dp[M-1][i]);
    
    printf("%.2f\n", res);
  }  
  
  return 0;
}

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

using namespace std;

typedef unsigned long long ull;

#define pb push_back
#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

int main(){
    int n, m;
    while(cin >> n >> m, n+m){
        vector<vector<double> > v;
        rep(i, n){
            vector<double> d; double p;
            rep(j, n){cin >> p; d.pb(p);}
            v.pb(d);
        }

        double dp[110][3];
        memset(dp, 0, sizeof(dp));
        dp[0][0] = dp[0][1] = dp[0][2] = 1;
        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]*v[k][j]);
                }
            }
        }
        printf("%.9f\n",max(dp[m-1][0], max(dp[m-1][1], dp[m-1][2])));
    }
}

C++: #include<iostream>
#include<iomanip>
#include<string>
#include<cstdlib>
#include<cmath>
#include<algorithm>

using namespace std;

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

		double dp[n][m];
		for(int i=0; i<n; i++)
			dp[i][0] = 1;

		for(int i=1; i<m; i++) {
			for(int j=0; j<n; j++) {
				double max = 0;
				for(int k=0; k<n; k++) {
					double value = dp[k][i-1] * data[k][j];
					if(value > max) max = value;
				}
				dp[j][i] = max;
			}
		}

		double ans = 0;
		for(int i=0; i<n; i++) {
			if(ans < dp[i][m-1]) ans = dp[i][m-1];
		}
		cout << fixed << setprecision(2) << ans;
	}
	return 0;
}

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

int main(){
  double dp[MAX][MAX],nae[MAX][MAX];
  int n,m;

  while(cin >> n >> m, n+m){
    fill(dp[0],dp[MAX-1],1);

    for(int i = 0 ; i < n ; i++)
      for(int j = 0 ; j < n ; j++)
	cin >> nae[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]*nae[j][k]);

    double ans = 0;
    for(int i = 0 ; i < n ; i++)
      for(int j = 0 ; j < n ; j++)
	ans = max(ans,dp[i][j]);

    ans = (int)(ans+0.005);
    printf("%.2f\n" , ans);
  }

  return 0;
}

C++: #include<stdio.h>
#define rep(i,n) for(i=0;i<n;i++)
double max(double a,double b){return a>b?a:b;}
int main(void)
{
  int n,m,i,j,k,t;
  double mat[100][100],dp[2][100],res;
  for(;;){
    scanf("%d%d",&n,&m); if(!n)break;
    rep(i,n)rep(j,n)scanf("%lf",mat[i]+j);
    t=0;res=0;
    rep(i,n)dp[1][i]=0,dp[0][i]=1;
    rep(i,m){rep(j,n)rep(k,n)dp[t^1][j]=max(dp[t^1][j],dp[t][k]*mat[j][k]);
      t^=1;
    }
    rep(i,n)res=max(res,dp[t^1][i]);
    printf("%.2f\n",res);
  }
  return 0;
}