149752025-02-10 14:12:40mateDinamitcpp17Accepted 50/506ms796 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
	int n,m,rob; cin >> n >> m >> rob;
    vector <vector <int>> v(n+1,vector <int> (m+1));
    vector <vector <vector <int>>> dp(n+1,vector <vector <int>> (m+1,vector <int> (rob+1, 1e9)));
    for(int i = 1;i <= n; i++){
        for(int j = 1; j <= n; j++){
            cin >> v[i][j];
        }
    }
    /*for(int i = 0;i <= n; i++){
        for(int j = 0; j <= n; j++){
            for(int l = 0; l <= k; l++){
                dp[i][j][l] = INT_MAX;
            }
        }
    }*/
    int x = 0;
    for(int k = 0; k <= rob; k++){
        for(int i = 1;i <= n; i++){
            for(int j = 1; j <= n; j++){
                x = v[i][j];
                for(int l = 0; l <= k; l++){
                    if(i == 1 && j == 1){
                        dp[i][j][k] = x;
                    }else{
                        dp[i][j][k] = min(dp[i][j][k],min(dp[i-1][j][k-l],dp[i][j-1][k-l]) + x);
                    }
                    x >>= 1;
                }
            }
        }
    }
    

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

    
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/01ms316 KiB
2Accepted0/06ms564 KiB
3Accepted2/22ms500 KiB
4Accepted2/22ms316 KiB
5Accepted3/32ms316 KiB
6Accepted3/32ms500 KiB
7Accepted2/26ms740 KiB
8Accepted3/36ms744 KiB
9Accepted2/21ms316 KiB
10Accepted2/21ms316 KiB
11Accepted3/31ms316 KiB
12Accepted3/31ms316 KiB
13Accepted2/22ms508 KiB
14Accepted3/32ms556 KiB
15Accepted2/26ms796 KiB
16Accepted3/36ms744 KiB
17Accepted2/26ms740 KiB
18Accepted3/36ms564 KiB
19Accepted2/26ms748 KiB
20Accepted3/36ms564 KiB
21Accepted2/26ms568 KiB
22Accepted3/36ms564 KiB