Cod sursa(job #2940837)

Utilizator Theodor17Pirnog Theodor Ioan Theodor17 Data 16 noiembrie 2022 17:09:27
Problema Bibel Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.98 kb
#include <fstream>

using namespace std;

ifstream cin("bibel.in");
ofstream cout("bibel.out");

const int NMAX = 10;
const long long inf = 2e18;

struct punct{

    long long x, y;

};

punct v[NMAX + 1];
long long dp[(1 << NMAX) + 1][NMAX + 1], n;

long long dist(punct a, punct b){
    return 1LL * (a.x - b.x) * (a.x - b.x) + 1LL * (a.y - b.y) * (a.y - b.y);
}

int main(){

    ios :: sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int idk = 0, x = 0, y = 0;
    while(cin >> idk && idk != 2){

        if(idk == 1){

            /*

                dp[mask][j] = distanta minima pt a lua bilele din masca, ultima bila luata fiind cea cu nr j

            */

            for(int i = 3; i < (1 << n); i++)
                for(int j = 1; j <= n; j++)
                    dp[i][j] = inf;

            long long ans = inf;

            if(n >= 1)
                dp[1][1] = dist(v[0], v[1]);

            if(n >= 2)
                dp[2][2] = dist(v[0], v[2]);
            else
                ans = dp[1][1];

            /*
            for(int i = 3; i < (1 << n); i++){
                for(int j = 1; j <= n; j++){

                    if((i & (1 << (j - 1))) == 0)
                        continue;

                    long long cmin = inf;

                    for(int p = 1; p <= n; p++){

                        if((i & (1 << (p - 1))) == 0 || p == j)
                            continue;

                        int new_mask = (i ^ (1 << (j - 1)));
                        dp[i][j] = min(dp[i][j], dp[new_mask][p] + dist(v[p], v[j]));
                    }
                }
            }
            */
            /*
            for(int i = 1; i <= n; i++)
                ans = min(ans, dp[(1 << n) - 1][i]);
            */
            cout << ans << "\n";

            continue;
        }


        cin >> x >> y;
        n++;

        v[n].x = x;
        v[n].y = y;

    }

    return 0;
}