Submission #1031657

#TimeUsernameProblemLanguageResultExecution timeMemory
1031657ezzzayRaisins (IOI09_raisins)C++14
100 / 100
378 ms53340 KiB
#include<bits/stdc++.h> using namespace std; #define ff first #define ss second #define pb push_back #define int long long const int N=52; int a[N][N]; int dp[N][N][N][N]; int ps[N][N]; int fun(int y, int x, int a, int b){ if(dp[y][x][a][b]<INT_MAX)return dp[y][x][a][b] ; if(y==a and x==b){ dp[y][x][a][b]=0; return 0; } for(int i=y;i<a;i++){ int A= ps[a][b]-ps[a][x-1]-ps[y-1][b]+ps[y-1][x-1]; dp[y][x][a][b]= min(dp[y][x][a][b], A+fun(y,x,i,b)+fun(i+1,x,a,b) ); } for(int i=x;i<b;i++){ int A=ps[a][b]-ps[a][x-1]-ps[y-1][b]+ps[y-1][x-1]; dp[y][x][a][b]= min(dp[y][x][a][b], A+fun(y,x,a,i)+fun(y,i+1,a,b)); } return dp[y][x][a][b]; } signed main(){ int n,m; cin>>n>>m; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ for(int y=1;y<=n;y++){ for(int z=1;z<=m;z++){ dp[i][j][y][z]=INT_MAX; } } } } for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ cin>>a[i][j]; ps[i][j]=ps[i][j-1]+ps[i-1][j]-ps[i-1][j-1]+a[i][j]; } } cout<<fun(1,1,n,m); // cout<<dp[1][1][n][m]; }
#Verdict Execution timeMemoryGrader output
Fetching results...