shtian • 2个月前
先贴我的代码:
/*********************************************************************
程序名:T3bow
版权: sht
日期: 2024-10-13
*********************************************************************/
#include <bits/stdc++.h>
using namespace std;
#define int long long
namespace sio {
int inn() {
int k = 0;
bool ok = 0;
char ch = getchar();
for (; !(ch <= '9' && ch >= '0');) {
if (ch == '-') {
ok ^= 1;
}
ch = getchar();
}
for (; (ch <= '9' && ch >= '0');) {
k = (k << 1) + (k << 3) + (ch ^ 48);
ch = getchar();
}
return ok ? -k : k;
}
struct In {
In operator >>(int &a) {
a = inn();
return {};
}
} in;
}
using namespace sio;
struct node {
int m, p, mm, pp, k;
} a[104];
int f[1000][1000];
int l[1000][1000];
signed main() {
/*
freopen("power.in", "r", stdin);
freopen("power.out", "w", stdout);*/
int n;
in >> n;
for (int i = 1; i <= n; i++) {
in >> a[i].mm >> a[i].pp >> a[i].m >> a[i].p >> a[i].k;
}
int ans = 0;
for (int i = 0; i <= 800; i++) {
for (int j = 0; j <= 800; j++) {
if (i < 400 || j < 400) {
f[i][j] = -1e9;
}
}
}
for (int i = 1; i <= n; i++) {
for (int jj = 400; jj >= -400; jj--) {
for (int kk = 400; kk >= -400; kk--) {
int j = jj + 400, k = kk + 400;
l[j][k] = max(f[j][k], f[j + a[i].mm][k + a[i].pp]);
if (j >= a[i].m && k >= a[i].p) {
l[j][k] = max(l[j][k], f[j - a[i].m][k - a[i].p] + a[i].k);
}
}
}
for (int j = 800; j >= 0; j--) {
for (int k = 800; k >= 0; k--) {
f[j][k] = l[j][k];
}
}
}
cout << f[400][400] << "\n";
return 0;
}
然后是测试点3输入:
3
1 7 7 8 6
9 9 7 3 5
注意到少了一行
评论:
请先登录,才能进行评论