0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-09 16:58:48 +00:00

1855. [Scoi2010]股票交易

https://hydro.ac/d/bzoj/record/6322eabd32ae6c3198cc9916
This commit is contained in:
Baoshuo Ren 2022-09-15 17:05:12 +08:00
parent 2e41798985
commit 9f201129c2
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
21 changed files with 123 additions and 0 deletions

63
BZOJ/1855/1855.cpp Normal file
View File

@ -0,0 +1,63 @@
#include <iostream>
#include <cstring>
#include <deque>
#include <tuple>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 2005;
int n, m, w, f[N][N];
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
memset(f, 0xcf, sizeof(f));
cin >> n >> m >> w;
for (int i = 1; i <= n; i++) {
f[i][0] = 0;
int ap, bp, as, bs;
cin >> ap >> bp >> as >> bs;
// [2]: 从 0 张开始买入
for (int j = 0; j <= as; j++) {
f[i][j] = -j * ap;
}
// [1]: 不操作
for (int j = 0; j <= m; j++) {
f[i][j] = std::max(f[i][j], f[i - 1][j]);
}
if (i - w - 1 > 0) {
// [3]: 买入
std::deque<int> q1;
for (int j = 0; j <= m; j++) {
while (!q1.empty() && q1.front() < j - as) q1.pop_front();
while (!q1.empty() && f[i - w - 1][q1.back()] + q1.back() * ap <= f[i - w - 1][j] + j * ap) q1.pop_back();
q1.push_back(j);
f[i][j] = std::max(f[i][j], f[i - w - 1][q1.front()] - (j - q1.front()) * ap);
}
// [4]: 卖出
std::deque<int> q2;
for (int j = m; ~j; j--) {
while (!q2.empty() && q2.front() > j + bs) q2.pop_front();
while (!q2.empty() && f[i - w - 1][q2.back()] + q2.back() * bp <= f[i - w - 1][j] + j * bp) q2.pop_back();
q2.push_back(j);
f[i][j] = std::max(f[i][j], f[i - w - 1][q2.front()] + (q2.front() - j) * bp);
}
}
}
cout << f[n][0] << endl;
return 0;
}

BIN
BZOJ/1855/data/1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/1855/data/1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/1855/data/10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/1855/data/10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/1855/data/2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/1855/data/2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/1855/data/3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/1855/data/3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/1855/data/4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/1855/data/4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/1855/data/5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/1855/data/5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/1855/data/6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/1855/data/6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/1855/data/7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/1855/data/7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/1855/data/8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/1855/data/8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/1855/data/9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/1855/data/9.out (Stored with Git LFS) Normal file

Binary file not shown.