43192023-03-24 11:42:47horvathabelDinamitcpp17Runtime error 10/504ms5280 KiB
#include <bits/stdc++.h>
using namespace std;
int mx=INT_MAX;
int main() {
	int n,m,k;
	cin>>n>>m>>k;
	vector<int> g[n+1];
	for (int i=0;i<n;i++){
		for (int j=0; j<m;j++){
			int x;
			cin>>x;
			g[i].push_back(x);
		}
	}
	vector<vector<vector<int>>> dp;
	dp.assign(n+1, vector<vector<int>> (m+1, vector<int>(k+1, mx)));
	int cnt=1; 
	for (int i=0; i<=k;i++){
		dp[0][0][i]=g[0][0]/cnt;
		cnt*=2;
	} 
	for (int i=0; i<n;i++){
		for (int j=0; j<m;j++){
				for (int z=0; z<=k;z++){
					if (i-1>=0){
						int cnt=1; 
						for (int p=0;p<=z;p++){					
					
							dp[i][j][z]=min(dp[i-1][j][z-p]+(g[i][j]/cnt),dp[i][j][z]);
							cnt*=2;  
						}
					}
					if (j-1>=0){
					int cnt=1; 
						for (int p=0;p<=z;p++){
							dp[i][j][z]=min(dp[i][j-1][z-p]+(g[i][j]/cnt), dp[i][j][z]);

							cnt*=2;  
						}
					}
					
					}
				
				
			}
		}
		cout<<dp[n-1][m-1][k];
	}

SubtaskSumTestVerdictTimeMemory
base10/50
1Accepted0/03ms1808 KiB
2Runtime error0/04ms2832 KiB
3Accepted2/23ms2448 KiB
4Accepted2/23ms2664 KiB
5Accepted3/33ms2616 KiB
6Accepted3/33ms2628 KiB
7Runtime error0/24ms3492 KiB
8Runtime error0/34ms3532 KiB
9Runtime error0/23ms2972 KiB
10Runtime error0/23ms3192 KiB
11Runtime error0/33ms3424 KiB
12Runtime error0/33ms3556 KiB
13Runtime error0/23ms3984 KiB
14Runtime error0/33ms3980 KiB
15Runtime error0/24ms4428 KiB
16Runtime error0/34ms4680 KiB
17Runtime error0/24ms4628 KiB
18Runtime error0/33ms4688 KiB
19Runtime error0/24ms4964 KiB
20Runtime error0/34ms5016 KiB
21Runtime error0/24ms5280 KiB
22Runtime error0/33ms5228 KiB