#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
#define int long long
#define pii pair<int,int>
#define vi vector<int>
#define ff first
#define ss second
#define sp << " " <<
#define all(x) x.begin(),x.end()
#define big(x) ((int)(x.size()))
using namespace std;
const int MOD = 1e9+7, LIM = 1e6+1, inf = 2e18;
const int N = (1LL<<11);
void solve() {
int n;
cin >> n;
int dp[n+1][n+1],f[n][n];
for (int i = 0;i<=n;i++) {
for (int j = 0;j<n;j++) {
dp[i][j] = inf;
if (i<n) cin >> f[i][j];
if (i == 1) dp[1][j] = 0;
}
}
for (int i = 1;i<=n;i++) {
for (int j = 0;j<n;j++) {
if (dp[i][j] == inf) continue;
if (i == n) continue;
int len = __lg((i-1)^i);
//j ile farklı lenli ama aynı >lenli
int oth = j^(1<<len);
oth >>= len;
oth <<= len;
for (int t = oth;t<oth+(1<<len);t++) {
dp[i+1][t] = min(dp[i+1][t],dp[i][j]+f[j][t]);
}
}
}
int ans = inf;
for (int i = 0;i<n;i++) ans = min(ans,dp[n][i]);
cout << ans << '\n';
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef Dodi
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
int t = 1;
//cin >> t;
while (t --> 0) solve();
}
# | 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... |