답안 #294024

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
294024 2020-09-08T14:29:52 Z kshitij_sodani 건포도 (IOI09_raisins) C++14
100 / 100
997 ms 26056 KB
#include <bits/stdc++.h>
using namespace std;
#define a first
#define b second
#define pb push_back

typedef long long llo;


int n,m;
int it[51][51];
int dp[51][51][51][51];
int find(int i,int j,int k,int l){
	if(dp[i][j][k][l]>-1){
		return dp[i][j][k][l];
	}
	dp[i][j][k][l]=0;
	for(int ii=i;ii<=k;ii++){
		for(int jj=j;jj<=l;jj++){
			dp[i][j][k][l]+=it[ii][jj];
		}
	}
	int ma=1e9;

	for(int ii=i;ii<k;ii++){
		ma=min(ma,find(i,j,ii,l)+find(ii+1,j,k,l));
	}
	for(int jj=j;jj<l;jj++){
		ma=min(ma,find(i,j,k,jj)+find(i,jj+1,k,l));

	}

	dp[i][j][k][l]+=ma;
	return dp[i][j][k][l];

}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n>>m;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>it[i][j];
		}
	}
	for(int i=0;i<n;i++){
		for(int  j=0;j<m;j++){
			for(int k=0;k<n;k++){
				for(int l=0;l<m;l++){
					dp[i][j][k][l]=-1;
					if(i==k and j==l){
						dp[i][j][k][l]=0;
					}
				}
			}
		}
	}
	cout<<find(0,0,n-1,m-1)<<endl;










	


	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 1024 KB Output is correct
7 Correct 1 ms 1152 KB Output is correct
8 Correct 10 ms 3456 KB Output is correct
9 Correct 18 ms 4992 KB Output is correct
10 Correct 28 ms 5888 KB Output is correct
11 Correct 23 ms 5120 KB Output is correct
12 Correct 82 ms 10496 KB Output is correct
13 Correct 140 ms 12920 KB Output is correct
14 Correct 38 ms 6144 KB Output is correct
15 Correct 182 ms 14080 KB Output is correct
16 Correct 16 ms 4864 KB Output is correct
17 Correct 69 ms 9472 KB Output is correct
18 Correct 484 ms 20216 KB Output is correct
19 Correct 788 ms 24524 KB Output is correct
20 Correct 997 ms 26056 KB Output is correct