#include <bits/stdc++.h>
#define pb push_back
#define int long long
using namespace std;
const int inf = 1e15 + 10;
const int N = 2048 + 10;
vector<vector<int> > c(N, vector<int>(N));
vector<vector<int> > dp[N];
void f(int node, int l, int r){
if(l == r){
dp[node].resize(1);
dp[node][0].resize(1);
dp[node][0][0] = 0;
return;
}
int m = (l + r)/2;
f(node * 2, l, m);
f(node * 2 + 1, m+1, r);
int sz = (r - l + 1);
dp[node].resize(sz);
for(int i = 0; i < sz; i++){
dp[node][i].resize(sz);
}
for(int i = 0; i < sz; i++){
for(int j = 0; j < sz; j++){
dp[node][i][j] = inf;
}
}
vector<vector<int> > dp2(sz/2, vector<int>(sz/2, inf));
for(int k = 0; k < sz/2; k++){
for(int l2 = 0; l2 < sz/2; l2++){
for(int r2 = 0; r2 < sz/2; r2++){
dp2[k][r2] = min(dp2[k][r2], dp[node*2+1][l2][r2] + c[k + l][l2 + l + sz/2]);
}
}
}
for(int l1 = 0; l1 < sz/2; l1++){
for(int k = 0; k < sz/2; k++){
for(int r2 = 0; r2 < sz/2; r2++){
dp[node][l1][r2 + sz/2] = min(dp[node][l1][r2 + sz/2], dp[node*2][l1][k] + dp2[k][r2]);
}
}
}
for(int l2 = 0; l2 < sz/2; l2++){
for(int r2 = 0; r2 < sz/2; r2++){
dp2[l2][r2] = inf;
}
}
for(int k = 0; k < sz/2; k++){
for(int l2 = 0; l2 < sz/2; l2++){
for(int r2 = 0; r2 < sz/2; r2++){
dp2[l2][k] = min(dp2[l2][k], dp[node*2+1][l2][r2] + c[l2 + l + sz/2][k + l]);
}
}
}
for(int r1 = 0; r1 < sz/2; r1++){
for(int l2 = 0; l2 < sz/2; l2++){
for(int k = 0; k < sz/2; k++){
dp[node][l2 + sz/2][r1] = min(dp[node][l2 + sz/2][r1], dp2[l2][k] + dp[node*2][k][r1]);
}
}
}
for(int l2 = 0; l2 < sz; l2++){
for(int r2 = 0; r2 < sz; r2++){
dp[node][l2][r2] = min(dp[node][l2][r2], dp[node][r2][l2]);
}
}
/*
for(int l1 = 0; l1 < sz/2; l1++){
for(int r1 = 0; r1 < sz/2; r1++){
for(int l2 = 0; l2 < sz/2; l2++){
for(int r2 = 0; r2 < sz/2; r2++){
dp[node][l1][r2 + sz/2] = min(dp[node][l1][r2 + sz/2], dp[node*2][l1][r1] + c[l2 + sz/2 + l][r1 + l] + dp[node*2+1][l2][r2]);
dp[node][l2 + sz/2][r1] = min(dp[node][l2 + sz/2][r1], dp[node*2+1][l2][r2] + c[r2 + sz/2 + l][l1 + l] + dp[node*2][l1][r1]);
}
}
}
}
*/
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n;
cin>>n;
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
cin>>c[i][j];
}
}
f(1, 0, n-1);
int ans = inf;
for(int l = 0; l < n; l++){
for(int r = 0; r < n; r++){
//cout<<l<<" "<<r<<" -> "<<dp[1][l][r]<<endl;
ans = min(ans, dp[1][l][r]);
}
}
cout<<ans<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
25 ms |
33696 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
25 ms |
33696 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
25 ms |
33696 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
25 ms |
33696 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |