205032026-01-07 13:18:06szabelrFestés (50 pont)cpp17Hibás válasz 26/50185ms10208 KiB
// Festés_clean.c=pp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <climits>
using namespace std;
int ar[100001][5][5];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m;
    cin >> n >> m;
    vector<int>sorar(n);
    for (int i = 0; i < n; i++)
    {
        int x; cin >> x;
        sorar[i] = x;
    }
    //m,kezdet,veg
    for (int i = 1; i <= m; i++)
    {
        for (int y = 1; y <= n; y++)
        {
            for (int z = y; z <= n; z++)
            {
                int x; cin >> x;
                ar[i][y][z] = x;
            }
        }
    }
    long long best_sum = 1e18;
    for (int bitmask = 0; bitmask <= (1 << n)-1; bitmask++)
    {
        long long sum = 0;
        for (int j = 0; j <= n - 1; j++)
        {
            if ((bitmask & (1 << j)) != 0)
                sum += sorar[j];
        }
        for (int i = 1; i <= m; i++)
        {
            vector<long long>dp(n + 1, 1e18);
            dp[0] = 0;
            for (int y = 1; y <= n; y++)
            {
                if ((bitmask & (1 << (y - 1))) != 0)
                    dp[y] = min(dp[y - 1],dp[y]);
                for (int z = 1; z <= y; z++)
                {
                   
                    dp[y] = min(dp[y], ar[i][z][y] + dp[z - 1]);
                    
                 }
                
            }
            sum += dp[n];
        }
        best_sum = min(best_sum, sum);
    }
    cout << best_sum;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
RészfeladatÖsszpontTesztVerdiktIdőMemória
base26/50
1Elfogadva0/01ms520 KiB
2Hibás válasz0/01ms316 KiB
3Elfogadva2/2103ms10036 KiB
4Hibás válasz0/21ms316 KiB
5Elfogadva3/33ms316 KiB
6Hibás válasz0/217ms1332 KiB
7Elfogadva2/2175ms10116 KiB
8Hibás válasz0/2179ms10036 KiB
9Hibás válasz0/2177ms10092 KiB
10Elfogadva2/2179ms10036 KiB
11Hibás válasz0/2178ms9948 KiB
12Hibás válasz0/2160ms9352 KiB
13Hibás válasz0/2172ms9248 KiB
14Elfogadva2/252ms10036 KiB
15Elfogadva3/354ms10064 KiB
16Elfogadva3/397ms10036 KiB
17Elfogadva2/296ms10120 KiB
18Elfogadva3/397ms10152 KiB
19Elfogadva2/2160ms9016 KiB
20Hibás válasz0/2171ms9540 KiB
21Hibás válasz0/2175ms10044 KiB
22Hibás válasz0/2177ms10072 KiB
23Hibás válasz0/2178ms10208 KiB
24Hibás válasz0/2177ms10036 KiB
25Elfogadva2/2185ms10076 KiB