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<double> > dp(m, vector<double>(n, 1.0));
		vector< vector<double> > data(n, vector<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][j] * data[j][k]);
				}
			}
		}
		double maximum = 0;
		for(int i = 0; i < n; ++i)
		{
			maximum = max(maximum, dp[m - 1][i]);
		}
		if((int)(maximum * 1000) % 10 >= 5)
		{
			printf("%.2f\n", maximum + 0.01);
		}
		else
		{
			printf("%.2f\n", maximum);
		}
	}
}

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

C++: #include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

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

VVD C;	// cost
VD prev, next;
int n, m;	// ì¿ð^¦éñ
int i, j, k;

double solve()
{
	double answer = -1.0;
	for ( i = 0; i < n; i++ ) prev[i] = 1.0;
	for ( k = 1; k < m; k++ )
	{
		for ( i = 0; i < n; i++ )
		{
			next[i] = -1.0;
			for ( j = 0; j < n; j++ )
			{
				double tmp = prev[j] * C[j][i];
				next[i] = max( next[i], tmp );
				answer = max( answer, next[i] );
			}
		}
		prev = next;
	}
	return answer;
}

int main( void )
{
	C = VVD( 100, VD( 100 ) );
	prev = VD( 100 );
	next = VD( 100 );

	while ( scanf( "%d%d", &n, &m ) != EOF && n > 0 && m > 0 )
	{
		for ( i = 0; i < n; i++ ) for ( j = 0; j < n; j++ ) scanf( "%lf", &C[i][j] );
		printf( "%.2lf\n", solve() );
	}

	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <queue>
#include <string>
#include <complex>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define repa(i,s,e) for(int i=s; i<=e; i++)
#define repd(i,s,e) for(int i=s; i>=e; i--)

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int MAX_N = 101;
const int MAX_M = 101;
int N, M;
double table[MAX_N][MAX_N];
double dp[MAX_M][MAX_N]; 

void solve() {
	rep(i,M) rep(j,N) dp[i][j] = 0.0;

	rep(i,N) dp[0][i] = 1.0;
	repa(i,1,M-1) {
		rep(j,N) {
			double maxval = 0.0;
			rep(k,N) {
				double s = dp[i-1][k] * table[k][j];
				maxval = max(s, maxval);
			}
			dp[i][j] = maxval;
		}
	}

	double maxval = 0.0;
	rep(i,N) {
		maxval = max(maxval, dp[M-1][i]);
	}
	printf("%.2f\n", maxval);
}

int main() {
	while(scanf("%d%d",&N,&M), N|M) {
		rep(i,N) {
			rep(j,N) {
				scanf("%lf", &table[i][j]);
			}
		}
		solve();
	}
}

C++: #include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-9;

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

int main() {
	while (cin >> n >> m, n || m) {
		REP(i, n) REP(j, n) scanf("%lf", &g[i][j]);
		
		memset(dp, 0, sizeof(dp));
		REP(i, n) dp[0][i] = 1.0;
		
		REP(i, m - 1) {
			REP(j, n) {
				REP(k, n) {
					chmax(dp[i + 1][k], dp[i][j] * g[j][k]);
				}
			}
		}
		
		double ans = 0;
		REP(i, n) chmax(ans, dp[m - 1][i]);
		printf("%.2lf\n", ans);
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int m,n;
double a[100][100],b[100][100];
double f(int p,int q,double r){
  int i;
  double mx=0;
  if(p==m){
    mx=r;
  }else if(b[p][q]==0||b[p][q]<r){
    b[p][q]=r;
    for(i=0;i<n;i++)
      mx=max(mx,f(p+1,i,r*a[q][i]));
  }
  return mx;
}
int main(){
  int i,j;
  double mx;
  while(cin>>n>>m&&n+m){
    for(i=0;i<n;i++)
      for(j=0;j<n;j++)
	cin>>a[i][j];
    memset(b,0,sizeof(b));
    mx=0;
    for(i=0;i<n;i++)
      mx=max(mx,f(1,i,1));
    printf("%.2lf\n",mx);
  }
  return 0;
}

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 + 1, VI(n + 1, 0));
		VVI dp(n + 1, VI(m + 1, 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);
	}
}