#include <bits/stdc++.h>
using namespace std;
#define pll pair<long long, long long>
#define mp make_pair
#define pb push_back
#define int long long
#define f first
#define s second
#define ld long double
#define sz(x) static_cast<int>((x).size())
#define i5 tuple<int,int,int,int,int>
#define all(x) x.begin(), x.end()
#define iii tuple<int,int,int>
#define eb emplace_back
const int maxn = 2050;
int mat[maxn][maxn], v[maxn];
signed main(){
int n;cin>>n;
//for(int i=0;i<n;i++)cin>>v[i];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cin>>mat[i][j];
}
}
vector<vector<int>> dp(n+1, vector<int>(n+1, 1e14));
for(int x=0;x<n;x++)dp[1][x]=0;
for(int i=1;i<n;i++){
for(int x=0;x<n;x++){
int lsb=(i & (-i)), u=(lsb==1?x:x & ~(lsb-1));
u ^= lsb;
//printf("i %lld, x %lld, lsb %lld, u %lld, dp[i][x] %lld\n", i, x, lsb,u, dp[i][x]);
for (int y=0; y < lsb;y++){
//printf("u+y %lld\n", u+y);
dp[i+1][u+y] = min(dp[i+1][u+y], dp[i][x] + mat[x][u+y]);
//printf("dp[i+1][u+y] %lld mat %lld\n", dp[i+1][u+y], mat[x][u+y]);
}
}
}
int ans=LLONG_MAX;
for(int x=0;x<n;x++){
ans=min(ans, dp[n][x]);
}
cout<<ans;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |