一步步的推进,尝试寻找最优解决方案!!
#include<cstdio> #include<iostream> #include<cstring> #include<algorithm> #define maxn 101 using namespace std; int list[maxn][maxn]; int main() { int n; while (cin >> n && n) { for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { scanf("%d", &list[j][i]); list[i][j] = list[j][i]; } } int ans = list[1][2]; for (int i = 3; i <= n; i++) { int t = 0x3f3f3f3f; for (int j = 2; j < i; j++) { t = min(t, (list[1][i] - list[1][j] + list[j][i]) / 2); } ans += t; } cout << ans << endl; } return 0; }