Go: // n×nの成長度表に現れる数字を重複を許してm-1個選んで掛け合わせる時の最大値を求める
// ->掛け算型のDP

package main

import (
	"bufio"
	"os"
	"strings"
	"strconv"
		"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 <utility>

using namespace std;

double table[100][100];
double result[100][100];

int main(){
	while(true){
		int n, m;
		cin >> n >> m;
		if(n == 0 && m == 0){ break; }
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				cin >> table[i][j];
			}
		}
		for(int i = 0; i < n; i++){ result[0][i] = 1.0; }
		for(int i = 1; i < m; i++){
			for(int j = 0; j < n; j++){
				double maxval = 0.0;
				for(int k = 0; k < n; k++){
					maxval = max(maxval, result[i - 1][k] * table[k][j]);
				}
				result[i][j] = maxval;
			}
		}
		double answer = 0.0;
		for(int i = 0; i < n; i++){
			answer = max(answer, result[m - 1][i]);
		}
		printf("%.2lf\n", answer);
	}
	return 0;
}

C++: #include <iostream>
#include <stdio.h>
using namespace std;

int main() {
	int i,j,k,m,n;
	double a,d[100][100],an[100];
	while(cin >> n >> m) {
		if (n==0 && m==0) break;
		for (i=0;i<n;i++) { an[i]=1; for (j=0;j<n;j++) cin >> d[i][j];}
		for (k=0;k<m-1;k++) {
			for (i=0;i<n;i++) { a=0; 
			  for (j=0;j<n;j++) a=a < an[i]*d[i][j] ? an[i]*d[i][j] : a;
			  an[i]=a;
		  }
	  }
	  for (i=0,a=0;i<n;i++) a= a < an[i] ? an[i] : a;
	  printf("%.2f\n",a);
  }  			  
  return 0;
}

C++: #include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

int main(){
    int n,m;
    while(cin >> n >> m,n){
        double table[105][105];
        rep(i,n){
            rep(j,n){
                cin >> table[i][j];
            }
        }

        double dp[105][105] = {{0}}; //????????????????????\????????\??????
        rep(i,105) dp[i][0] = 1;
        range(i,1,m){
            rep(j,n){
                rep(k,n){
                    dp[j][i] = max(dp[j][i], dp[k][i - 1] * table[k][j]);
                }
            }
        }
        
        double maxi = 0;
        rep(i,n){
            maxi = max(maxi, dp[i][m - 1]);
        }
        cout <<fixed << setprecision(2) << maxi << endl;
    }
}

C++: 
#include<iostream>
#include<vector>
#include<iomanip>
using namespace std;
int n,m;
double M,manure[100][100];

void check(double size,int num,int pre)
{
  if(num>=m){
    if(M<size)M=size;
    return;
  }
  for(int i=0;i<n;i++)check(size*manure[pre][i],num+1,i);
}

int main()
{
  cout<<setprecision(2);
  cout<<setiosflags(ios::fixed);
  while(cin>>n>>m,n|m){
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)cin>>manure[i][j];
    M=0;
    for(int i=0;i<n;i++)check(1.0,1,i);
    cout<<M<<endl;
  }
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

double dp[200][200];
double h[200][200];
int main() {
	int n, m;
	while (scanf("%d%d", &n, &m), n) {
		rep(i, n)rep(j, n)scanf("%lf", &h[i][j]);
		memset(dp, 0, sizeof(dp));
		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] * h[j][k]);
		double Max = 0.;
		rep(i, n)Max = max(Max, dp[m - 1][i]);
		printf("%.2lf\n", Max);
	}
}

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,k;
  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(j,n)
      dp[0][j]=1.0;

    for(i=1;i<m;i++)
      for(j=0;j<n;j++){
	temp=0;
	rep(k,n)
	  temp=max(temp,dp[i-1][k]*grow[k][j]);
	dp[i][j]=temp;
      }
      
    double sum=0;

    rep(j,n)
      sum=max(sum,dp[m-1][j]);
 
    printf("%.2f\n",sum);
  }

}

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+0.005);
}

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

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]);
		}
		printf("%.2lf\n",ret);
	}
	
}

C++: #include <iostream>
#include <cmath>
using namespace std;

const int MAX_N = 100, MAX_M = 100;
const double EPS = 1e-10;

int n,m;
long double g[MAX_N][MAX_N], dp[2][MAX_N];

int main()
{
    int m, n;
    while(cin >> n >> m && n) {
        for(int i = 0; i < n; i++) 
            for(int j = 0; j < n; j++) 
                cin >> g[i][j];

        for(int i = 0; i < n; i++) 
            dp[0][i] = dp[1][i] = 1.0;
        
        for(int i = 0; i < m - 1; i++) {
            for(int j = 0; j < n; j++) {
                for(int k = 0; k < n; k++) {
                    dp[(i+1) % 2][k] = max(dp[(i+1) % 2][k], dp[i % 2][j] * g[j][k]);
                }
            }
        }
        long double ret = 0.0;
        for(int i = 0; i < n; i++) 
            ret = max(ret, dp[(m-1) % 2][i]);
        printf("%.2Lf\n", ret);

    }
    
}