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<iomanip>
#include<algorithm>
#define shosu(x) fixed<<setprecision(x)
using namespace std;

int n,m;
double ef[105][105];

double func(){
	double ans=0,dp[105][105]={0};
	for(int i=0;i<m;i++){
		dp[0][i]=1;
	}
	for(int i=1;i<n;i++){
		for(int j=0;j<m;j++){
			double tmp=0;
			for(int k=0;k<m;k++){
				tmp=max(tmp,dp[i-1][k]*ef[k][j]);
			}
			dp[i][j]=tmp;
		}
	}
	for(int i=0;i<m;i++){
		ans=max(ans,dp[n-1][i]);
	}
	return ans;
}

int main(){
	cout<<shosu(2);
	while(1){
		cin>>n>>m;
		if(n==0&&m==0) break;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cin>>ef[i][j];
			}
		}
		cout<<func()<<endl;
	}
}

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

constexpr int MAX = 100;

int n, m;
double board[MAX][MAX];
double dp[MAX][MAX];

int main() {
	while (1) {
		std::cin >> m >> n;
		if (m + n == 0)
			break;
		std::memset(dp, 0, sizeof(dp));
		for (int i = 0; i < m; ++i) {
			for (int j = 0; j < m; ++j)
				std::cin >> board[i][j];
		}
		for (int i = 0; i < m; ++i)
			dp[0][i] = 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 ans = 0;
		for (int i = 0; i < m; ++i)
			ans = std::max(ans, dp[n - 1][i]);
		std::cout << std::fixed << std::setprecision(2) << ans << std::endl;
	}
	return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<math.h>

double hi[100][100],len,max,mae[100],ato[100];

int main(){
	int i,j,n,m,k;
	
	while(0<=scanf("%d%d",&n,&m)){
		if(n==0&&m==0)break;
		memset(hi,0,sizeof(hi));
		
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				scanf("%lf",&hi[i][j]);
			}
		}
		
		for(i=0;i<n;i++){
			mae[i]=1;
		}
		
		for(i=1;i<m;i++){
			memset(ato,0,sizeof(ato));
			
			for(j=0;j<n;j++){
				//printf("%lf ",mae[j]);
			}
			//printf("\n");
			
			for(j=0;j<n;j++){
				for(k=0;k<n;k++){
					if(ato[j]<mae[k]*hi[k][j])ato[j]=mae[k]*hi[k][j];
				}
			}
			
			memcpy(mae,ato,sizeof(ato));
		}
		max=0;
		for(i=0;i<n;i++)if(max<mae[i])max=mae[i];
		
		printf("%.2lf\n",max);
	}
	return 0;
}

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

#define ll (long long)
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)


using namespace std;


int main(void){
    
    int drugnumber;
    int drugcounter;
    /* x????¨????,y?????´????????? */
    double drugeffect[120][120] = {0};
    int i,j,k,l;
    double max = 0;
    double answer[100] = {0};
    
    while(cin >> drugnumber >> drugcounter,drugnumber+drugnumber)
    {
        double combination[120][120] = {0};
        /*??£??\*/
        FOR(j, 1, drugnumber+1)
        FOR(i, 1, drugnumber+1)
        cin >> drugeffect[j][i];
        
        //cout << drugeffect[2][1];
        
        for(k = 1;k <= drugnumber; k++)
            combination[1][k] = 1.0;
        //cout << combination[1][2] << endl;
        
        /* j?????¬?????°,i????????°*/
        
        for(i = 1; i< drugcounter;i++)
            for(j = 1; j<= drugnumber;j++)
            {
                for(k = 1; k<=drugnumber;k++)
                {
                    if((combination[i][j] * drugeffect[j][k]) >= combination[i+1][k])
                        combination[i+1][k] = combination[i][j]*drugeffect[j][k];
                     //cout << combination[i+1][j] << " ";
                    /*
                     if((combination[j][i] * drugeffect[j][i]) >= combination[j][i])
                     combination[j][i+1] = combination[j][i] * drugeffect[j][i];
                     */
                }
            }
        
    
    for(i = 1 ; i<= drugnumber;i++)
        if(max <  combination[drugcounter][i])
            max = combination[drugcounter][i];
    
        answer[l] = max;
        max = 0;
        l++;
        
    }
    REP(i,l)
    printf("%.2f\n",answer[i]);
    return 0;
    
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

int n, m;
double g[111][111];

double dp[111][111];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(2);

  while(cin >> n >> m, n || m) {
    rep(i, n) rep(j, n) cin >> g[i][j];

    fill(dp[0], dp[111], 0.0);
    rep(i, n) dp[0][i] = 1.0;
    rep(i, m-1) {
      rep(j, n) {
	rep(k, n) {
	  chmax(dp[i+1][j], dp[i][k]*g[k][j]);
	}
      }
    }
    double ans = 0;
    rep(i, n) chmax(ans, dp[m-1][i]);
    cout << ans << endl;
  }

  return 0;
}

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

double memo[101][101];
double data[101][101];
int n;

void initData(){
  for(int i=0;i<101;i++)
    for(int j=0;j<101;j++)
      data[i][j] = 1;
}

void inputData(){
  for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
      cin >> data[i][j];
}

double solve(int m, int p){ //回数,直前の肥料
  
  if(!m) return 1;
  if(memo[m][p]) return memo[m][p];

  double ans = 0;
  for(int i=n;i>0;i--) ans = max(ans, solve(m-1, i)*data[p][i]);
  
  return memo[m][p] = ans;
}

int main(){
  
  int  m;
  
  while(true){
    cin >> n >> m;
    if(!n && !m) break;
    
    memset(memo, 0, sizeof(memo));
    initData();
    inputData();

    printf("%.2f\n", solve(m, 0));
  }
}

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

int n,m;
double ans;
double dp[101][101];
double up[101][101];
int main(void){
	for(int i=1;i<=100;i++){
		up[i][0]=1.0;
	}
	while(1){
		memset(dp,0,sizeof(dp));
		ans=0;
		cin >> n >> m;
		if(n==0 && m==0)break;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				cin >> up[j][i];
			}
		}
		dp[0][0]=1;
		for(int i=1;i<=m;i++){
			for(int j=1;j<=n;j++){
				for(int k=0;k<=n;k++){
					dp[i][j]=max(dp[i][j],dp[i-1][k]*up[j][k]);
				}
				if(i==m)ans=max(ans,dp[i][j]);
			}
		}
		printf("%0.2f\n",ans);
	}
    return 0;
}