# 2.6日提高组题目打卡

2023-02-06 22:57:42

``````#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> PII;
#define x first
#define y second
#define ms(a,s) memset(a, s, sizeof a);
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a)
const int mod = 1e6+7;
const int inf = 0x3f3f3f3f;
const int N = 1010;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int a[N];
int f[N][N], f2[N][N];
void slove() {
memset(f, 127, sizeof f);
int n;
cin >> n;
for(int i = 1; i <= n; i ++ ) {
cin >> a[i];
a[i + n] = a[i];
}
for(int i = 1; i <= 2 * n; i ++ ) {
a[i] += a[i - 1];
f[i][i] = 0;
}
for(int l = 1; l < n; l ++ ) {
for(int i = 1; i + l <= 2 * n; i ++ ) {
int j = i + l;
for(int k = i; k < j; k ++ ) {
f[i][j] = min(f[i][j], f[i][k] + f[k + 1][j] + a[j] - a[i - 1]);
f2[i][j] = max(f2[i][j], f2[i][k] + f2[k + 1][j] + a[j] - a[i - 1]);
}
}
}
int ans1 = INT_MAX, ans2 = 0;
for(int i = 1; i <= n; i ++ ) {
ans1 = min(ans1, f[i][i + n - 1]);
ans2 = max(ans2, f2[i][i + n - 1]);
}
cout << ans1 << '\n' << ans2;
}
int main()
{
int t = 1;

//	cin >> t;

while(t --) {
slove();
}

return 0;
}``````

...全文
12 回复 打赏 收藏 举报

3.2w+

2023-02-06 22:57

刷题！