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 <stdio.h>
#include <string.h>
//
//ツテツスツトツサツブツミツッツシツδδ督づ崢づヲ
//
//
 
double max(double a, double b)
{
    if (a > b){
        return (a);
    }
    return (b);
}
 
int main(void)
{
    int i, j, k;
    int n, m;
    double gr[100][100];
    double dp[100][100];
    double ans;
    int upd;
    
    while (1){
        scanf("%d%d", &n, &m);
        
        if (n + m == 0){
            break;
        }
        
        for (i = 0; i < n; i++){
            for (j = 0; j < n; j++){
                scanf("%lf", &gr[i][j]);
            }
        }
        
        memset(dp, 0, sizeof(dp));
        for (i = 0; i < n; i++){
            dp[0][i] = 1;
        }
        
        ans = 1.00;
        for (i = 1; i < m; i++){
            for (j = 0; j < n; j++){
                upd = 0;
                for (k = 0; k < n; k++){
                    if (upd == 0){
                        dp[i][j] = dp[i - 1][k] * gr[k][j];
                        upd = 1;
                    }
                    else {
                        dp[i][j] = max(dp[i][j], dp[i - 1][k] * gr[k][j]);
                    }
                }
            }
        }
        
        for (i = 0; i < n; i++){
            ans = max(ans, dp[m - 1][i]);
        }
        
        printf("%.2lf\n", ans);
        
    }
    
    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() {
	repa(i,0,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]);
	}
	cout << maxval << endl;
}

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

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

using namespace std;

int main(){
	
	int n,m;
	double table[101][101];
	double dp[2][101];
	while(cin>>n>>m&&!(n==0&&m==0)){
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++)
				cin>>table[i][j];
		}
		fill(dp[0],dp[0]+101,1);
		fill(dp[1],dp[1]+101,0);

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

		double maxNum=0;
		for(int i = 0; i < n; i++){
			maxNum=max(maxNum,prv[i]);
		}

		double ret=maxNum;
		printf("%.2f\n",ret);
	}

	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cassert>
#include<cmath>
#define EPS 1e-10
using namespace std;

int m,n;
double total;
double dp[110][110];
int Just;
vector<double> matrix[110];
void rec(int next,int counter,double sam){
 
  if(counter >= m){
    dp[Just][m] = max(dp[Just][m],sam);
    return;
  }
  for(int i=0;i<n;i++){
   
    rec(i,counter+1,sam*matrix[next][i]);
  }  
}


int main(){
  
  double In;
 
  while(cin >> n >> m && n && m){
    for(int i=0;i<=n;i++)matrix[i].clear();
  
    for(int i=109;i>=0;i--)for(int j=0;j<110;j++)dp[j][i] = 0;
   
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	cin >> In;
	matrix[i].push_back(In);
      }
    }
  


    double ans = -1;
 
      for(int I=0;I<n;I++){
	Just = I;
	rec(I,1,1.0);
	ans = max(ans,dp[Just][m]);
      }
    
    printf("%.2f\n",ans);

  }
  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cassert>
#include<cmath>
#define EPS 1e-10
using namespace std;
typedef pair<double,int> P;
vector<P> vec;
int m,n;
double total;
double rec(int pre,int counter){
  if(counter > m){
    return vec[pre].first;
  }
  return rec(vec[pre].second,counter+1)*vec[pre].first;
}


int main(){
  
  double In;
 
  while(cin >> n >> m && n && m){
    vector<double> matrix[n+2];
    //int pre[n+2][m+2]; 
    double sam[n+2];
    int pos[n+2]; 
    total = 1.0;
    vec.clear();
    for(int i=0;i<=n;i++)sam[i] = 0;
    total = 1.0;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	cin >> In;
	matrix[i].push_back(In);
	if(sam[i] - In < EPS){
	  sam[i] = In;
	  pos[i] = j;
	}
      }
    }

    for(int i=0;i<n;i++){
      vec.push_back(P(sam[i],pos[i]));
    }
    /*
    cout << "sam = ";
    for(int i=0;i<n;i++)cout << sam[i] << " ";
    cout << endl;

    cout << "pre = ";
    for(int i=0;i<n;i++)cout << pos[i] << " ";
    cout << endl;
    */
    double ans = -1;
    for(int I=0;I<n;I++)ans = max(ans,rec(I,m));
    printf("%.2f\n",ans);

  }
  return 0;
}

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

int n, m;
double grow[100][100];
double dp[110][110];

int main() {
    while(std::cin >> n >> m, n + m) {
    
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            std::cin >> grow[i][j];
        }
    }

    for(int i = 0; i < n; ++i) {
        dp[0][i] = 1.;
    }
    for(int i = 1; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            dp[i][j] = 0.;
        }
    }

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

    printf("%.2f\n", ((int)(*std::max_element(dp[m - 1], dp[m - 1] + n) * 100 + 0.5)) / 100.);


    }
}