# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
531895 | __Variatto | 건포도 (IOI09_raisins) | C++17 | 243 ms | 21016 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define ll long long
const int MAX=51, MAXV=1e9+10;
int n, m, dp[MAX][MAX][MAX][MAX], p[MAX][MAX], t[MAX][MAX];
int pref(int x1, int y1, int x2, int y2){
return p[x2][y2]+p[x1-1][y1-1]-p[x1-1][y2]-p[x2][y1-1];
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin>>n>>m;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
cin>>t[i][j];
p[i][j]=p[i-1][j]+p[i][j-1]-p[i-1][j-1]+t[i][j];
}
}
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
if(i==1 && j==1) continue;
for(int x=1; x<=n-i+1; x++){
for(int y=1; y<=m-j+1; y++){
dp[x][y][x+i-1][y+j-1]=MAXV;
//pion
for(int l=y; l<=y+j-2; l++)
dp[x][y][x+i-1][y+j-1]=min(dp[x][y][x+i-1][y+j-1], dp[x][y][x+i-1][l]+dp[x][l+1][x+i-1][y+j-1]);
//poziom
for(int l=x; l<=x+i-2; l++)
dp[x][y][x+i-1][y+j-1]=min(dp[x][y][x+i-1][y+j-1], dp[x][y][l][y+j-1]+dp[l+1][y][x+i-1][y+j-1]);
dp[x][y][x+i-1][y+j-1]+=pref(x, y, x+i-1, y+j-1);
}
}
}
}
cout<<dp[1][1][n][m]<<"\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |