153842025-02-19 10:19:25zsebiDinamitcpp17Hibás válasz 13/5074ms944 KiB
// dinamit.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <climits>
#include <cmath>
#include<algorithm>
#define ll long long 
using namespace std;
ll n, m, k;
ll dp[41][41][41];
ll x[41][41];
int main()
{
    cin >> n >> m >> k;
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j)cin >> x[i][j];
    for (int i = 1; i <= n; ++i)
    {
        ll mini = LLONG_MAX;
        for (int l = 0; l <= k; ++l)
        {
            for (int o = 0; o <= l; ++o)
            {
                ll a = (pow(2, l - o));
                mini = min(mini, dp[i - 1][1][o] + x[i][i] / a);
            }
            dp[i][1][l] = mini;
        }
    }
    for (int j = 1; j <= n; ++j)
    {
        ll mini = LLONG_MAX;
        for (int l = 0; l <= k; ++l)
        {
            for (int o = 0; o <= l; ++o)
            {
                ll a = (pow(2, l - o));
                mini = min(mini, dp[1][j-1][o] + x[1][j] / a);
            }
            dp[1][j][l] = mini;
        }
    }
    for (int i = 2; i <= n; ++i)
    {
        for (int j = 2; j <= m; ++j)
        {
            for (int l = 0; l <= k; ++l)
            {
                ll mini =LLONG_MAX;
                for (int o = 0; o <= l; ++o)
                {
                    ll a = (pow(2, l - o));
                    mini = min(mini,min(dp[i-1][j][o], dp[i][j-1][o]) + x[i][j] /a );
                }
                dp[i][j][l] = mini;
            }
        }
    }
    ll ans = LLONG_MAX;

   for (int l = 0; l <= k; ++l)
        ans = min(dp[n][n][l], ans);
   cout << ans;
 /*for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= m; ++j)
        {
            for (int l = 0; l <= k; ++l)
            {
                cout << dp[i][j][l] << " ";
            }
            cout << " ";
        }
        cout << "\n";
    }
  */
    return 0;
}

// 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
base13/50
1Elfogadva0/01ms500 KiB
2Elfogadva0/074ms820 KiB
3Hibás válasz0/22ms820 KiB
4Hibás válasz0/22ms868 KiB
5Elfogadva3/32ms820 KiB
6Elfogadva3/32ms820 KiB
7Hibás válasz0/271ms820 KiB
8Hibás válasz0/374ms712 KiB
9Elfogadva2/26ms416 KiB
10Hibás válasz0/24ms316 KiB
11Elfogadva3/34ms464 KiB
12Hibás válasz0/36ms316 KiB
13Hibás válasz0/218ms576 KiB
14Hibás válasz0/318ms524 KiB
15Elfogadva2/274ms860 KiB
16Hibás válasz0/374ms892 KiB
17Hibás válasz0/274ms860 KiB
18Hibás válasz0/374ms860 KiB
19Hibás válasz0/274ms908 KiB
20Hibás válasz0/374ms744 KiB
21Hibás válasz0/274ms808 KiB
22Hibás válasz0/374ms944 KiB