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 <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, 0.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 = 0; i < n; ++i)
		{
			dp[0][i] = 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] * 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<cstdio>
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int n,m;
	while(scanf("%d%d",&n,&m),n){
		double g[n][n],c[n][m],ans=0;
		rep(i,n){
			rep(j,n)scanf("%lf",g[i]+j);
			rep(j,m)c[i][j]=j?0:1;
		}
		rep(i,m-1)rep(j,n)rep(k,n)if(c[k][i+1]<c[j][i]*g[j][k])
		c[k][i+1]=c[j][i]*g[j][k];
		rep(i,n)if(c[i][m-1]>ans)ans=c[i][m-1];
		printf("%.2f\n",ans);
	}
	return 0;
}

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;
  long double M;
  while(cin>>n>>m,n|m){
    vector< vector<long double> >manure(n,vector<long double>(n)),dp(m,vector<long double>(n,0.0));
    for(i=0;i<n;i++)for(j=0;j<n;j++)cin>>manure[i][j];
    for(j=0;j<n;j++)dp[0][j]=1.0;
    for(i=1;i<m;i++){
      for(j=0;j<n;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[m-1][j]);
    cout<<M<<endl;
  }
}

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];
      }
    }
    double dp[n][m];
    for(int i = 0; i < n; ++i){
      dp[i][0] = 1.0;
    }
    for(int i = 1; i < m; ++i){
      for(int j = 0; j < n; ++j){
	double maximum = -1;
	for(int k = 0; k < n; ++k){
	  double t = table[k][j] * dp[k][i-1];
	  if( gt(t,maximum) ){
	    maximum=t;
	  }
	}
	dp[j][i] = maximum;
      }
    }
    
    for(int i = 0; i < n; ++i){
      if( gt( dp[i][m-1], answer ) )
	answer = dp[i][m-1];
    }
    printf("%.2lf\n",answer);

  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

double t[105][105];	// ツ行ツづ個値ツづ債前ツ嘉アツ与ツつヲツつスツ氾ャツ猟ソ,ツ療アツづ個値ツづ債債。ツ嘉アツ与ツつヲツつスツ氾ャツ猟ソ
double dp[105][105];

int main()
{
	int n, m;

	while (cin >> n >> m && n && m ){
		memset (t, 0.0, sizeof (t ) );
		memset (dp, 0.0, sizeof (dp ) );

		rep (i, n ){
			rep (j, n ){
				cin >> t[i][j];
			} // end rep
		} // end rep
		rep (j, n ){
			dp[1][j] = 1.0;
		} // end rep
		for (int i = 2; 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]*t[k][j] );
				} // end for
			} // end for
		} // end for

		double res = 0.0;
		for (int i = 0; i < n; i++ ){
			res = max (res, dp[m][i] );
		} // end for

		printf ("%.02lf\n", res );
	} // end while

	return 0;
}

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 >> n >> m;
		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<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;
  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(i,n)
      cout<<"M"<<maxi[i]<<endl;//?¢????
    */
    rep(j,n)
      dp[0][j]=1.0;

    for(i=1;i<n;i++)
      for(j=0;j<n;j++)
	dp[i][j]=dp[i-1][maxi[j]]*grow[maxi[j]][j];

    double sum=0;

    rep(j,n)
      sum=max(sum,dp[n-1][j]);

    //sum+=0.005;
    printf("%.2f\n",sum);

  }

}

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 n,m;
  while(cin>>n>>m,n+m){
    vector<vector<double> > d(n,vector<double>(n));
    vector<double> now(n,1),past(n,1);
  
    rep(i,n)rep(j,n)cin>>d[i][j];
    rep(times,m-1){
      rep(i,n){
	rep(j,n){
	  // i is past , j is now
	  now[j] = max(now[j],past[i] * d[i][j]);
	}
      }
      //      rep(i,now.size())cout<<now[i]<<" ";cout<<endl;
      past = now;
    }
    double ret = -1;
    rep(i,now.size())ret=max(ret,now[i]);
    printf("%.2f\n",ret);
  }
  
  
}