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>
#define INF 0
using namespace std;
int main(){
	int n,m;
	double t[200][200];
	while(cin>>n>>m,n||m){
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
				cin>>t[i][j];
		double dp[200][200];
		for(int i=0;i<=n;i++)
		for(int j=0;j<n;j++)
		dp[j][i]=INF;
		for(int i=0;i<n;i++)
		dp[i][0]=1.0;
		for(int i=1;i<n;i++)
		for(int j=0;j<n;j++)
		for(int k=0;k<n;k++)
		dp[j][i]=max(dp[j][i],dp[k][i-1]*t[k][j]);
		double ans=INF;
		for(int i=0;i<n;i++)
		ans=max(ans,dp[i][n-1]);
		printf("%.2lf\n",ans);
		
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
using namespace std;
double key[100][100];
double table[100][100];

void Init(int n, int m){
	for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) table[i][j] = 0;
}

double memo(int cur, int count, int limit, int kind){
	if(table[cur][count]) return table[cur][count];
	if(count==limit) return 1.0;
	double Max = 0;
	int prev = 0;
	for(int i = 0; i < kind; i++){
		double tmp = memo(i, count+1, limit, kind);
		if(Max <= tmp){
			//if(Max*key[prev][cur] < tmp*key[i][cur]){
				Max = tmp;
				prev = i;
			//}
		}
	}
	table[cur][count] = Max*key[prev][cur];
	return table[cur][count];
}

int main(){
	int n, m;
	while(cin >> n >> m && ((n!=0)||(m!=0))){
		Init(n, m);
		for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) cin >> key[i][j];
		for(int i = 0; i < n; i++) table[i][0] = memo(i, 0, m-1, n);
		double max = 0;
		for(int i = 0; i < n; i++) if(max < table[i][0]) max = table[i][0];
		printf("%0.2f\n", max);
	}

	return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <climits>
using namespace std;

typedef vector <double> VD;
typedef vector <VD> VVD;
typedef vector <int> VI;

class info
{
public:
	int		id;
	double	score;
};

VVD C;	// cost
vector <info> prev;
vector <info> next;
int n;	// ì¿ÌíÞ
int m;	// ì¿ð^¦éñ
double answer;

void solve()
{
	prev = vector <info>( n );
	next = vector <info>( n );

	for ( int i = 0; i < n; i++ )
	{
		prev[i].id = i;
		prev[i].score = 1.0;
	}

	for ( int k = 1; k < m; k++ )
	{
		for ( int i = 0; i < n; i++ )
		{
			next[i].score = INT_MIN;
			for ( int j = 0; j < n; j++ )
			{
				double tmp = prev[j].score * C[prev[j].id][i];
				next[i].score = max( next[i].score, tmp );
			}
		}
		prev = next;
	}

	answer = prev[0].score;
	for ( int i = 1; i < n; i++ )
		answer = max( answer, prev[i].score );
}

int main( void )
{
	while ( cin >> n >> m && n > 0 && m > 0 )
	{
		C = VVD( n, VD( n, 0.0 ) );

		// üÍ
		for ( int i = 0; i < n; i++ )
		{
			for ( int j = 0; j < n; j++ )
			{
				cin >> C[i][j];
			}
		}

		solve();

		cout.setf( ios::fixed );
		cout.precision( 2 );
		cout << answer << endl;
	}

	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][j] = max(dp[k][j], dp[k-1][i]*p[i][j]);
    
    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 <cmath>
#include <cstdio>
#include <iostream>
using namespace std;

int n, m;
double g[100][100];
double dp[101][100];

double rec(int a, int b){ //a回目，前に与えた肥料b
	if(dp[a][b]>0) return dp[a][b];
	
	double ret=1.0;

	if(a==m-1) ret=1.0;
	else{
		double t=-1;
		for(int i=0; i<n; ++i){
			double s=g[b][i]*rec(a+1, i);	
			//printf("s=%lf\n", s);
			if(s>t) t=s;
		}
		ret=t;
		//printf("t=%lf\n", t);
	}
	
	return dp[a][b]=ret;
}

int main(){
	while(1){
		scanf(" %d %d", &n, &m);
		if(n==0) break;
		for(int i=0; i<n; ++i)
		for(int j=0; j<n; ++j)
		scanf(" %lf", &g[i][j]);
		
		for(int i=0; i<101; ++i)
		for(int j=0; j<100; ++j)
		dp[i][j]=-1.0;		
		
		double ans=0;
		for(int i=0; i<n; ++i){
			double tmp=rec(0, i);
			if(tmp>ans) ans=tmp;	
		}
		
		/*
		for(int i=0; i<m; ++i){
			for(int j=0; j<n; ++j){
				printf("%.4lf ", dp[i][j]);		
			}
			printf("\n");
		}
		*/
		
		ans*=100;
		ans=round(ans);
		ans/=100;
		printf("%.2lf\n", ans);
	}
}

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

double dp[101][101];//dp[i][j]=i??????????????\?????\??????j?????¨??????????????????????????§???
double grow[101][101];//i=??´??????j=??????
		

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

C++: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#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 all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1<<30;
int main(){
	int n,m;
	while(cin>>n>>m,n+m){
		double in[110][110]={0},dp[110][110]={0};
		rep(i,n)rep(j,n)cin>>in[i][j];
		rep(i,n)dp[0][i]=1;
		rep(i,m-1)rep(j,n)rep(k,n)
			dp[i+1][k]=max(dp[i+1][k],dp[i][j]*in[j][k]);
		double out=0;
		rep(i,n)out=max(out,dp[m-1][i]);
		cout<<shosu(2)<<out<<endl;
	}
}