思路:bitset优化dp,具体怎么做请看这篇博客 https://www.cnblogs.com/EchoZQN/p/13320776.html
#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e4 + 50;
int INF = 1e9;
int n, m;
bitset<maxn> bit1[maxn], bit2, s;
struct node
{
int x, st;
} a[maxn * 5], b[maxn];
int id[maxn * 5];
bool cmp(node p1, node p2){
return p1.x < p2.x;
}
int main() {
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; i++){
scanf("%d", &a[i].x);
a[i].st = i;
}
for(int i = 1; i <= m; i++){
scanf("%d", &b[i].x);
b[i].st = i;
}
sort(a + 1, a + n + 1, cmp);
sort(b + 1, b + m + 1, cmp);
int p = 1;
int cnt = 1;
for(int i = 1; i <= n; i++){
int fg = 1;
while(a[i].x >= b[p].x && p <= m){
if(fg){
cnt++;
bit1[cnt] = bit1[cnt - 1];
fg = 0;
}
bit1[cnt].set(b[p].st - 1);
p++;
}
id[a[i].st] = cnt;
}
s[m - 1] = 1;
int ans = 0;
for(int i = n; i >= 1; i--){
bit2 = ((bit2 >> 1) | s) & bit1[id[i]];
if(bit2[0] == 1) ans++;
}
printf("%d
", ans);
return 0;
}