// Mide la tabla de la cadena de matrices. Menor de 3 intentos, con -O2.
#include <chrono>
#include <cstdio>
#include <random>
#include <vector>

#include "interval_dp.h"

int main() {
    std::puts("Cadena de matrices, dimensiones al azar entre 1 y 50, menor de 3 intentos");
    std::puts("    n   combinaciones        ms");
    double previous = 0;
    for (int n : {200, 400, 800, 1600}) {
        std::mt19937 rng(11);
        std::vector<long long> d(static_cast<std::size_t>(n) + 1);
        for (long long& x : d) x = 1 + static_cast<long long>(rng() % 50);
        double best = 1e18;
        long long combinations = 0;
        for (int attempt = 0; attempt < 3; attempt++) {
            combinations = 0;
            const auto start = std::chrono::steady_clock::now();
            matrix_chain(d, &combinations);
            const auto stop = std::chrono::steady_clock::now();
            best = std::min(best, std::chrono::duration<double, std::milli>(stop - start).count());
        }
        if (previous > 0) {
            std::printf("%5d %15lld %9.1f   x%.1f\n", n, combinations, best, best / previous);
        } else {
            std::printf("%5d %15lld %9.1f\n", n, combinations, best);
        }
        previous = best;
    }
}
