20412022-12-15 17:25:041478Dinamitcpp11Elfogadva 50/509ms6312 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> p32;
typedef pair<ll, ll> p64;
typedef pair<double, double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int>> vv32;
typedef vector<vector<ll>> vv64;
typedef vector<vector<p64>> vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
double eps = 1e-12;
#define forn(i, e) for (ll i = 0; i < e; i++)
#define forsn(i, s, e) for (ll i = s; i < e; i++)
#define rforn(i, s) for (ll i = s; i >= 0; i--)
#define rforsn(i, s, e) for (ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout << #x << " = " << x << ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())

const int N_MAX = 150;
int a[N_MAX][N_MAX];
int dp[N_MAX][N_MAX][N_MAX];

int main()
{
    //ifstream cin("be.txt");

    int n;
    int m;
    int numberOfBooms;

    cin >> n;
    cin >> m;
    cin >> numberOfBooms;

    // vector<vector<int>> a(n + 1, vector<int>(m + 1));
    // vector<vector<vector<int>>> dp(numberOfBooms + 1, vector<vector<int>>(n + 1, vector<int>(m + 1)));

    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            cin >> a[i][j];
        }
    }

    for (int k = 0; k <= numberOfBooms; k++)
    {
        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= m; j++)
            {
                dp[k][i][j] = INT32_MAX;
                int halfer = 1;
                int actualValue = INT32_MAX;

                for (int l = k; l >= 0; l--)
                {
                    if (actualValue == 0)
                        break;

                    actualValue = a[i][j] / halfer;

                    if (i == 1 && j == 1)
                    {
                        dp[k][i][j] = actualValue;
                    }
                    if (i != 1)
                    {
                        dp[k][i][j] = min(dp[k][i][j], dp[l][i - 1][j] + actualValue);
                    }
                    if (j != 1)
                    {
                        dp[k][i][j] = min(dp[k][i][j], dp[l][i][j - 1] + actualValue);
                    }

                    halfer *= 2;
                }
            }
        }
    }

    /*for (int k = 0; k <= numberOfBooms; k++)
    {
        cout << k << ": " << ln;
        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= m; j++)
            {
                cout << dp[k][i][j] << " ";
            }
            cout << ln;
        }
        cout << ln;
    }*/

    cout << dp[numberOfBooms][n][m];

    return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base50/50
1Elfogadva0/03ms1916 KiB
2Elfogadva0/09ms4356 KiB
3Elfogadva2/23ms2464 KiB
4Elfogadva2/23ms2660 KiB
5Elfogadva3/33ms2864 KiB
6Elfogadva3/33ms3068 KiB
7Elfogadva2/28ms5092 KiB
8Elfogadva3/39ms5252 KiB
9Elfogadva2/23ms3724 KiB
10Elfogadva2/23ms3856 KiB
11Elfogadva3/33ms3932 KiB
12Elfogadva3/33ms4064 KiB
13Elfogadva2/24ms4652 KiB
14Elfogadva3/34ms4748 KiB
15Elfogadva2/29ms5756 KiB
16Elfogadva3/39ms5860 KiB
17Elfogadva2/29ms6008 KiB
18Elfogadva3/39ms5896 KiB
19Elfogadva2/29ms6024 KiB
20Elfogadva3/39ms6236 KiB
21Elfogadva2/29ms6308 KiB
22Elfogadva3/39ms6312 KiB