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<cstdio>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define INF 1e6
using namespace std;

int main(){
	int n,m;
	while(cin>>n>>m,n||m){
		double dt[n][n],dp[m][n];
		rep(i,n)rep(j,n)cin>>dt[i][j];
		rep(i,m)rep(j,n)dp[i][j]=-1*INF;
		rep(i,n)dp[0][i]=1.0;
		rep(i,m-1){
			rep(j,n){
				rep(k,n){
					dp[i+1][k]=max(dp[i+1][k],dp[i][j]*dt[j][k]);
				}
			}
		}
		double ans=-1;
		rep(i,n)ans=max(ans,dp[m-1][i]);
		printf("%.2f\n",ans);
	}
	return 0;
}

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

int main(){
	int n, m;
	double dp[101][101], hiryou[101][101];
	while(cin >>n >>m){
		if(n == 0 && m == 0) break;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				cin >>hiryou[i][j];
			}
		}
		for(int i = 0; i < n; i++){
			dp[0][i] = 1.0;
		}
		for(int i = 1; i < m; i++){
			for(int j = 0; j < n; j++){
				dp[i][j] = 0.0;
				for(int k = 0; k < n; k++){
					if(dp[i - 1][k] * hiryou[k][j] > dp[i][j]) dp[i][j] = dp[i - 1][k] * hiryou[k][j];
				}
			}
		}
		//for(int i = 0; i < n; i++){
		//	for(int j = 0; j < m; j++){
		//		printf("%5.5f ", dp[j][i]);
		//	}
		//	cout <<endl;
		//}
		double ans = 0.0;
		for(int i = 0; i < n; i++){
			if(dp[m - 1][i] > ans) ans = dp[m - 1][i];
		}
		printf("%.2f\n", ans);
	}
	return 0;
}

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

using namespace std;

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

      queue<pair<pair<int,int>,double> >qu;
      for(int i=0;i<n;i++)
	  qu.push(make_pair(make_pair(1,i),1.0));

      double ans=0;
      double dp[m+2][n];
      memset(dp,0,sizeof(dp));
      while(!qu.empty())
	{
	  int cnt=qu.front().first.first;
	  int num=qu.front().first.second;
	  double score=qu.front().second;
	  qu.pop();
	  if(dp[cnt][num]>=score)
	    continue;
	  dp[cnt][num]=score;
	  if(cnt>=m)
	    {
	      ans=max(ans,score);
	      continue;
	    }
	  for(int i=0;i<n;i++)
	    {
	      qu.push(make_pair(make_pair(cnt+1,i),score*data[num][i]));
	    }
	}
      //      cout<<fixed<<setprecision(2)<<(1.231)<<endl;
      //      cout<<fixed<<setprecision(2)<<(1.235)<<endl;

      cout<<fixed<<setprecision(2)<<(ans)<<endl;
    }

}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m;
double po=1;
double data[105][105];
double ans=1;
void check(int x,int y);
int main(void){
    for(;;){
        po=1;
        ans=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>>data[i][j];
            }
        }
        check(0,0);


        printf("%.2lf\n",po);


    }
	return 0;
}

void check(int x,int y){
    if(y==n){
        //cout<<ans<<endl;
        po=max(po,ans);
        return;
    }
    if(y==0){
        for(int i=0;i<n;i++){

            check(i,y+1);

        }

    }
    else {
        for(int i=0;i<n;i++){
            ans*=data[x][i];
            //cout<<x<<"-"<<i<<endl;
            check(i,y+1);
            ans/=data[x][i];
        }

    }



}

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

int main(){
  int n,m; 
  double data[101][101],tree[101][101];
  while ( cin >> n >> m ,n+m ) {
    for ( int i = 1; i <= n; i++ ) {
      for ( int j = 1; j <= n; j++ ) cin >> tree[i][j];
    }

    for ( int i = 1; i <= n; i++ ) {
      for ( int j = 1; j <= n; j++ ) data[i][j] = -1.0;
    }


    for ( int i = 1; i <= n; i++ ) data[i][1] = 1.0;
    
    int tmp;
    int cnt = 0;
    for( int i = 1; i <= n; i++ ) {
      cnt++;
      tmp = cnt;
      for( int j = 1; j < n; j++ ) {
	for( int k = 1; k <= n; k++ ) {
	  if ( data[i][j+1] < data[i][j] * tree[tmp][k] ) {
	    data[i][j+1] = data[i][j] * tree[tmp][k];
	    tmp = k;
	  }
	}
      }
    }
    double maxv = -1.0;
    for( int i = 1; i <= n; i++ ) maxv = max( data[i][n], maxv );

    printf("%.2f\n",maxv);

  }
  return 0;
}

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

int main() {
	int n, m;
	while(cin >> n >> m, n || m) {
		double gr[128][128] = {0};
		double dptab[128][128] = {0};
		for(int i = 0; i < 128; i++) {
			dptab[0][i] = 1.0;
		}
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				cin >> gr[i][j];
			}
		}

		for(int i = 1; i < m; i++) {
			for(int j = 0; j < n; j++) {
				for(int k = 0; k < n; k++) {
					dptab[i][j] = max(dptab[i][j], dptab[i - 1][k] * gr[k][j]);
				}
			}
		}

		double ans = -1;
		for(int i = 0; i < n; i++) {
			ans = max(dptab[m-1][i], ans);
		}

		printf("%.2f\n", ans);
	}
}

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

double dp[105][105];
double g[105][105];

double solve(int n, int m){
    rep(i,n) dp[0][i] = 1;
    range(i,1,m){
        rep(j,n){
            rep(k,n){
                dp[i][j] = max(dp[i][j], dp[i - 1][k] * g[k][j]);
            }
        }
    }

    double retval = 0;
    rep(i,n){
        retval = max(dp[m - 1][i], retval);
    }
    return retval;
}

int main(){
    int n, m;
    while(cin >> n >> m, n||m){
        rep(i,105) rep(j,105) dp[i][j] = 0;
        rep(i,n) rep(j,n) cin >> g[i][j];
        cout << solve(n, m) << endl;
    }
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<iomanip>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
#define N 110
#define M 110
double dp[M][N];
double g[M][M];
int n,m;

double shishagonyu2(double x){
  ll a=x*1000;
  a=a/10+(a%10>=5?1:0);
  x=(double)a/100.0;
  return x;
}

int main(){
  //cout<<shishagonyu2(5.5555)<<endl;
  while(cin>>n>>m&&n+m){
    lol(i,n)lol(j,n)cin>>g[i][j];
    lol(i,n)dp[0][i]=1.0;
    lol(i,m)lol(j,n)dp[i+1][j]=0.0;
    lol(i,m){
      lol(j,n){
	lol(k,n){
	  dp[i+1][k]=max(dp[i+1][k],dp[i][j]*g[j][k]);
	}
      }
    }
    double ans=0;
    lol(i,n)ans=max(ans,dp[m-1][i]);
    ans=shishagonyu2(ans);
    cout<<fixed<<setprecision(2)<<ans<<endl;
  }
  return 0;
}