平面切割
#include<bits/stdc++.h>
long long n;
int main()
{
ios::sync_with_stdio,cin.tie(0),cout.tie(0);
cin>>n;
cout<<n*n-n+2;
return 0;
}餐厅&餐巾
#include <cstdio>
#include <climits>
int n;
int r[MAXN];
int a, u, b, v, c;
long long dp[MAXN][MAXR];
int buy[MAXN][MAXR];
int fast[MAXN][MAXR];
int slow[MAXN][MAXR];
void solve() {
// Initialize DP table
for (int i = 0; i <= n; ++i) {
for (int j = 0; j < MAXR; ++j) {
dp[i][j] = LLONG_MAX;
}
}
dp[0][0] = 0;
for (int day = 1; day <= n; ++day) {
for (int prev = 0; prev < MAXR; ++prev) {
if (dp[day-1][prev] == LLONG_MAX) continue;
int required = r[day];
int available = prev;
// Calculate how many we need to buy
for (int purchase = 0; purchase <= required; ++purchase) {
int remaining = available + purchase - required;
if (remaining < 0) continue;
// Calculate how many to send to fast and slow laundry
for (int send_fast = 0; send_fast <= remaining; ++send_fast) {
for (int send_slow = 0; send_slow <= remaining - send_fast; ++send_slow) {
long long cost = dp[day-1][prev] + purchase * a + send_fast * b + send_slow * c;
// Calculate next day's available
int next_available = remaining - send_fast - send_slow;
// Check if this is better than current solution
if (cost < dp[day][next_available]) {
dp[day][next_available] = cost;
buy[day][next_available] = purchase;
fast[day][next_available] = send_fast;
slow[day][next_available] = send_slow;
}
}
}
}
}
}
// Find the minimal cost
long long min_cost = LLONG_MAX;
int best_remain = 0;
for (int remain = 0; remain < MAXR; ++remain) {
if (dp[n][remain] < min_cost) {
min_cost = dp[n][remain];
best_remain = remain;
}
}
// Output the minimal cost
printf("%lld\n", min_cost);
// Backtrack to find the solution
int remain = best_remain;
int solution[MAXN][6] = {0};
int fast_arrival[MAXN] = {0};
int slow_arrival[MAXN] = {0};
for (int day = n; day >= 1; --day) {
solution[day][0] = r[day];
solution[day][1] = buy[day][remain];
solution[day][2] = fast[day][remain];
solution[day][3] = slow[day][remain];
// Calculate arrivals from previous days
if (day > u) {
solution[day][4] = fast[day-u][remain + fast[day][remain] + slow[day][remain]];
}
if (day > v) {
solution[day][5] = slow[day-v][remain + fast[day][remain] + slow[day][remain]];
}
// Update remain for previous day
remain = remain + fast[day][remain] + slow[day][remain] - solution[day][1];
}
// Output the solution
for (int day = 1; day <= n; ++day) {
printf("%d %d %d %d %d %d\n",
solution[day][0], solution[day][1], solution[day][2],
solution[day][3], solution[day][4], solution[day][5]);
}
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", &r[i]);
}
scanf("%d %d %d %d %d", &a, &u, &b, &v, &c);
solve();
return 0;
}