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 <iomanip>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>

#include <numeric>
#include <algorithm>
#include <functional>

#include <cctype>

#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define rep(i,n) for(unsigned int i=0;i<(n);i++)
#define tr(it,container) for(typeof(container.begin()) it = container.begin(); \
                                                  it != container.end(); ++it)
#define mp(a,b) make_pair((a),(b))

typedef long long ll;
typedef complex<double> P;
const int dx[] = {1,0,-1,0};
const int dy[] = {0,-1,0,1};
const double EPS = 1e-9;
const int days[] = {31,28,31,30,31,30,31,31,30,31,30,31};
const int daysleap[] = {31,29,31,30,31,30,31,31,30,31,30,31};

int main(){
    while(true){
        int n,m;
        cin >> n >> m;
        if(n==0) break;
        vector<double> maxi(n,1.0);
        vector<vector<double> > M(n,vector<double>(n));
        rep(i,n) rep(j,n) cin >> M[i][j];
        for(int i=0;i<m-1;i++){
            vector<double> next(n,-1);
            for(int j=0;j<n;j++){
                for(int k=0;k<n;k++){
                    next[k] = max(next[k],maxi[j] * M[j][k]);
                }
            }
            maxi = next;
        }
        cout << fixed << setprecision(2) << *max_element(all(maxi)) << endl;
    }
    return 0;
}

C++: #include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int n,m;
    double g[100][100],dp[100][100];
    while(scanf("%d%d",&n,&m),n||m){
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++)
                scanf("%lf",&g[i][j]);

            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][j]=max(dp[i][j],dp[i-1][k]*g[k][j]);

        printf("%.2f\n",*max_element(dp[m-1],dp[m-1]+n));
        }
    return 0;
}

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<stdio.h>
double dp[2][100];
double ch[100][100];
double max(double a,double b){return a>b?a:b;}
int main(){
	int n,m;
	int i,j,k;
	while(1){
	scanf("%d %d",&n,&m);
	if(n==0)return 0;
	for(i=0;i<n;i++)for(j=0;j<n;j++)scanf("%lf",&ch[i][j]);
	for(i=0;i<n;i++)dp[0][i]=1.0f;
	for(i=1;i<m;i++){
		for(j=0;j<n;j++){
			dp[i%2][j]=0.0f;
			for(k=0;k<n;k++)dp[i%2][j]=max(dp[i%2][j],dp[(i+1)%2][k]*ch[k][j]);
		}
	}
	double ans=0.0f;
	for(i=0;i<n;i++)ans=max(ans,dp[(m+1)%2][i]);
	printf("%.2lf\n",ans);
	}
}

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

using namespace std;

int n,m;
double dp[101][101];
double t[101][101];

double solve(int times, int prev){
  if(dp[times][prev] != -1) return dp[times][prev];
  if(times == m) return dp[times][prev] = 1;

  double tmp=-1;
  for(int i=0;i<n;i++){
    if(times == 0){
      tmp = max(tmp, solve(times+1, i) * 1);
    }else{
      tmp = max(tmp, solve(times+1, i) * t[prev][i]);
    }
  }
  
  return dp[times][prev] = tmp;
}

int main(void){
  while(cin >> n >> m){
    if(!(n|m)) break;
    fill((double *)dp, (double *)dp+101*101, -1);
    int ret;
    double retd;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	cin >> t[i][j];
      }
    }
    retd = solve(0,0) * 100;
    /*
    if(ret%10 >= 5){
      ret += 10;
    }
    ret /= 10;
    */
    printf("%.2lf\n", round(retd) /  100);
  }
}

C++: #include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define Rep(i,n) for(int i = 1 ; i < n ; i++)
#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],0);
    rep(i,n) rep(j,n) cin >> nae[i][j]; 
   
    rep(i,n) dp[0][i] = 1.0;
    Rep(i,m) rep(j,n) rep(k,n)
      dp[i][j] = max(dp[i][j],dp[i-1][k]*nae[k][j]);

    double ans = 0;
    rep(i,n) rep(j,n)
      ans = max(ans,dp[i][j]);

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

  return 0;
}

C++: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
using namespace std;

void func(int N,int M){

	double table[N+1][N+1],dp[M+1][N+1];

	for(int i = 0; i <= M; i++){
		for(int k = 0; k <= N; k++)dp[i][k] = 0.0;
	}

	for(int i = 1; i <= N; i++){
		for(int k = 1; k <= N; k++){
			scanf("%lf",&table[i][k]);
		}
	}

	for(int i = 1; i <= N; i++)dp[1][i] = 1.0;

	for(int i = 2; i <= M; i++){
		for(int k = 1; k <= N; k++){
			for(int p = 1; p <= N; p++){
				dp[i][k] = max(dp[i][k],dp[i-1][p]*table[p][k]);
			}
		}
	}

	double ans = -1.0;

	for(int i = 1; i <= N; i++){
		ans = max(ans,dp[M][i]);
	}

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

}

int main(){

	int N,M;
	while(true){
		scanf("%d %d",&N,&M);
		if(N == 0 && M == 0)break;

		func(N,M);
	}

    return 0;
}

C++: #include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
using namespace std;

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

double dt[102][102];
double dp[102][102];
int n;

double dfs(int d,int v){
	if(abs(dp[d][v]+1)>1e-6)return dp[d][v];
	if(d == 0) return 1.0;
	double r=-1;
	for(int i = 0 ; i < n ; i++){
		r = max(r,dfs(d-1,i) * dt[i][v]);
	}

	return dp[d][v] = r;
}

int main(void){
	int m;
	while(cin>>n>>m,n+m){

		rep(i,n)
			rep(j,n)cin>>dt[i][j];
		rep(i,102)rep(j,102)dp[i][j] = -1;
		
		//rep(i,n)rep(j,n)cout<<dt[i][j]<<(j==n-1?'\n':' ');


		double r = 0;
		rep(i,n){
			r = max(r,dfs(m-1,i));
		}
		printf("%lf\n",r);
	}
}