0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-08 16:38:47 +00:00

#1541. 【2022.09.07 NOIP 模拟】单调栈

https://sjzezoj.com/submission/55988
This commit is contained in:
Baoshuo Ren 2022-09-07 21:33:47 +08:00
parent ab3df8d7c7
commit aabd9221e1
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
56 changed files with 236 additions and 0 deletions

71
S2OJ/1541/1541.cpp Normal file
View File

@ -0,0 +1,71 @@
#include <iostream>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 305,
M = 1e5 + 5;
const int mod = 1e9 + 7;
int n, m, b[N], fa[N];
long long f[N][M];
std::vector<int> g[N];
bool vis[N];
void dfs(int u) {
std::fill_n(f[u] + 1, m + 1, 1);
for (const int& v : g[u]) {
dfs(v);
for (int j = 1; j <= m + 1; j++) {
f[u][j] = (f[u][j] * f[v][j - vis[v]]) % mod;
}
}
if (u) {
for (int i = 1; i <= m + 1; i++) {
f[u][i] = (f[u][i] + f[u][i - 1]) % mod;
}
}
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> b[i];
}
for (int i = 1; i <= n; i++) {
vis[i] = true;
if (b[i] == -1) {
fa[i] = 0;
} else {
fa[i] = b[i];
for (int j = b[i] + 1; j < i; j++) {
if (fa[j] <= b[i]) {
fa[j] = i;
vis[j] = false;
}
}
}
}
for (int i = 1; i <= n; i++) {
g[fa[i]].emplace_back(i);
}
dfs(0);
cout << f[0][m + 1] << endl;
return 0;
}

BIN
S2OJ/1541/data/ex_stack1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/ex_stack1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/ex_stack2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/ex_stack2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/problem.conf (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack11.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack11.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack12.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack12.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack13.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack13.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack14.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack14.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack15.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack15.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack16.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack16.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack17.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack17.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack18.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack18.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack19.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack19.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack20.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack20.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack21.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack21.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack22.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack22.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack23.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack23.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack24.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack24.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack25.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack25.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1541/data/stack9.out (Stored with Git LFS) Normal file

Binary file not shown.