原题链接
数据结构优化DP
前置知识:二维树状数组 e.g.https://www.luogu.com.cn/problem/P4514
思路如下:
代码如下:
#include <cstdio>
#include <cctype>
using namespace std;
inline int read() {
int x = 0, f = 0; char ch = getchar();
while (!isdigit(ch)) f = ch == '-', ch = getchar();
while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
return f ? -x : x;
}
inline void print(int x) {
if (x < 0) putchar('-'), x = -x;
if (x < 10) putchar(x + '0');
else {
print(x / 10);
putchar(x % 10 + '0');
}
}
const int N = 2050;
int n, m;
int tr[4][N][N];
void addtr(int type, int x, int y, int k) {
for (int i = x; i < N