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

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

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<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;
  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(i,n)
      cout<<"M"<<maxi[i]<<endl;//?¢????
    */
    rep(j,n)
      dp[0][j]=1.0;

    for(i=1;i<n;i++)
      for(j=0;j<n;j++)
	dp[i][j]=dp[i-1][maxi[j]]*grow[maxi[j]][j];

    double sum=0;

    rep(j,n)
      sum=max(sum,dp[n-1][j]);
    cout<<sum<<endl;
    sum+=0.005;
    printf("%.2f\n",sum);

  }

}

C++: #define _USE_MATH_DEFINES
#define INF 10000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int,string> P;

static const double eps = 1e-8;

double dp[101][101];
double table[100][100];

int main(){

	int n,m;
	while(~scanf("%d %d",&n,&m)){
		if(n==m && m==0) break;
		for(int y=0;y<n;y++){
			for(int x=0;x<n;x++){
				scanf("%lf",&table[y][x]);
			}
		}

		fill((double*)dp,(double*)dp+101*101,0.0);
		for(int i=0;i<n;i++) dp[0][i] = 1.0;

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

		double res = -1.0;
		for(int i=0;i<n;i++) res = max(res,dp[m-1][i]);

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

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define rep(i,k,n) for(int i = k ; i < n ; i++ )
double G[101][101];
int main(){
  int n,m;
  while( cin >> n >> m,n+m){

    rep(i,1,n+1)
      rep(j,1,n+1)cin >> G[i][j];

    double dp[101][101];

    fill(dp[0],dp[101],0);

    rep(j,0,n+1)dp[1][j] = 1;

    double mx = 0;
    rep(i,1,n+1){
      rep(j,1,n+1){
	rep(k,1,n+1){
	  dp[i][j] = max(dp[i][j],dp[i-1][k] * G[k][j]);
	}
      }
    }
    rep(j,1,n+1)mx = max(mx,dp[n][j]);
    printf("%.2f\n",mx);
  }
  return 0;
}

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

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

C++: #include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
using namespace std;

#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)

double dt[102][102];
double dp[102][102];
int n;

double dfs(int d,int v){
	if(abs(dp[d][v]+1)>1e-6)return dp[d][v];
	if(d == 0) return 1.0;
	double r=-1;
	for(int i = 0 ; i < n ; i++){
		r = max(r,dfs(d-1,i) * dt[i][v]);
	}

	return dp[d][v] = r;
}

int main(void){
	int m;
	while(cin>>n>>m,n+m){

		rep(i,n)
			rep(j,n)cin>>dt[i][j];
		rep(i,102)rep(j,102)dp[i][j] = -1;
		
		//rep(i,n)rep(j,n)cout<<dt[i][j]<<(j==n-1?'\n':' ');


		double r = 0;
		rep(i,n){
			r = max(r,dfs(m-1,i));
		}
		printf("%.2f\n",r+1/2*(1/10)*2);
	}
}

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

int main(){
  int n,m;
  double In;
 
  while(cin >> n >> m && n && m){
    vector<double> matrix[n];
    double mex = 0,sam[n];
    for(int i=0;i<n;i++)sam[i] = -1;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	cin >> In;
	matrix[i].push_back(In);
	sam[j] = max(sam[j],In);
      }
    }

    mex = 1;
    for(int i=0;i<m-1;i++)mex*=sam[i];
    
    printf("%.2f\n",round(mex));


  }
  return 0;
}

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<n;i++){
		dp[0][i]=1;
	}
	for(int i=1;i<m;i++){
		for(int j=0;j<n;j++){
			double tmp=0;
			for(int k=0;k<n;k++){
				tmp=max(tmp,dp[i-1][k]*ef[k][j]);
			}
			dp[i][j]=tmp;
		}
	}
	for(int i=0;i<n;i++){
		ans=max(ans,dp[m-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 <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n, m;
        cin >> n >> m;
        if(n == 0)
            return 0;

        vector<vector<double> > x(n, vector<double>(n));
        for(int i=0; i<n; ++i){
            for(int j=0; j<n; ++j){
                cin >> x[i][j];
            }
        }

        vector<double> y(n, 1.0);
        while(--m > 0){
            vector<double> z(n, 0.0);
            for(int i=0; i<n; ++i){
                for(int j=0; j<n; ++j){
                    z[i] = max(z[i], y[j] * x[j][i]);
                }
            }
            y = z;
        }

        double ret = *max_element(y.begin(), y.end());
        printf("%.2f\n", ret);
    }
}