43202023-03-24 11:52:02horvathabelDinamitcpp17Accepted 50/508ms5352 KiB
#include <bits/stdc++.h>
using namespace std;
using ll=long long; 
int mx=INT_MAX;
int main() {
	int n,m,k;
	cin>>n>>m>>k;
	vector<ll> 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<ll>>> dp;
	dp.assign(n+1, vector<vector<ll>> (m+1, vector<ll>(k+1, mx)));
	ll cnt=g[0][0]; 
	for (int i=0; i<=k;i++){
		dp[0][0][i]=cnt;
		cnt=cnt/2;
	} 
	cout<<endl; 
	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){
						ll cnt=g[i][j]; 
						for (int p=0;p<=z;p++){					
					
							dp[i][j][z]=min(dp[i-1][j][z-p]+cnt,dp[i][j][z]);
							cnt=cnt/2; 
						}
					}
					if (j-1>=0){
					ll cnt=g[i][j]; 
						for (int p=0;p<=z;p++){
							dp[i][j][z]=min(dp[i][j-1][z-p]+cnt, dp[i][j][z]);

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

SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1820 KiB
2Accepted0/08ms3228 KiB
3Accepted2/23ms2456 KiB
4Accepted2/23ms2668 KiB
5Accepted3/33ms2932 KiB
6Accepted3/33ms3092 KiB
7Accepted2/28ms4284 KiB
8Accepted3/38ms4240 KiB
9Accepted2/23ms3460 KiB
10Accepted2/23ms3412 KiB
11Accepted3/33ms3668 KiB
12Accepted3/33ms3620 KiB
13Accepted2/24ms3860 KiB
14Accepted3/34ms4204 KiB
15Accepted2/28ms4964 KiB
16Accepted3/38ms4964 KiB
17Accepted2/28ms4960 KiB
18Accepted3/38ms5144 KiB
19Accepted2/28ms5088 KiB
20Accepted3/38ms5096 KiB
21Accepted2/28ms5096 KiB
22Accepted3/38ms5352 KiB