205022026-01-07 13:14:33szabelrFestés (50 pont)cpp17Wrong answer 22/50282ms30784 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 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;
    }
    vector<vector<vector<int>>> ar(m + 1, vector<vector<int>>(n + 1, vector<int>(n + 1)));
    //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;
            }
        }
    }
    int best_sum = INT_MAX;
    for (int bitmask = 0; bitmask <= (1 << n); bitmask++)
    {
        int 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, INT_MAX);
            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
SubtaskSumTestVerdictTimeMemory
base22/50
1Accepted0/01ms316 KiB
2Wrong answer0/01ms316 KiB
3Wrong answer0/2158ms26164 KiB
4Wrong answer0/21ms316 KiB
5Accepted3/33ms564 KiB
6Wrong answer0/225ms3380 KiB
7Accepted2/2254ms30732 KiB
8Wrong answer0/2275ms30772 KiB
9Wrong answer0/2273ms30748 KiB
10Accepted2/2256ms30772 KiB
11Wrong answer0/2254ms30772 KiB
12Wrong answer0/2250ms28224 KiB
13Wrong answer0/2259ms28212 KiB
14Accepted2/289ms19764 KiB
15Accepted3/390ms19760 KiB
16Accepted3/3164ms26256 KiB
17Accepted2/2164ms26164 KiB
18Accepted3/3153ms26124 KiB
19Accepted2/2229ms27700 KiB
20Wrong answer0/2259ms29236 KiB
21Wrong answer0/2250ms30532 KiB
22Wrong answer0/2273ms30772 KiB
23Wrong answer0/2254ms30772 KiB
24Wrong answer0/2273ms30772 KiB
25Wrong answer0/2282ms30784 KiB