大意: 给定序列$a,b$, 每次可以任取两个相同大小的$a_i,b_j$删除$a_i,b_j$左侧所有元素, 花费为e, 得分1, 最后结束时必须再花费之前删除元素的个数, 不得分. 初始能量$s$, 求最大得分方案.
这题关键是注意到$\frac{s}{e}$的范围比较小, 直接暴力dp即可..
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
//head #ifdef ONLINE_JUDGE
const int N = 1e6+10;
#else
const int N = 111;
#endif int n, m, s, e;
vector<int> g[N];
int dp[N], a[N]; int main() {
scanf("%d%d%d%d", &n, &m, &s, &e);
REP(i,1,n) scanf("%d", a+i);
REP(i,1,m) {
int t;
scanf("%d", &t);
g[t].pb(i);
}
memset(dp,0x3f,sizeof dp);
dp[0] = 0;
int ans = 0;
REP(i,1,n) PER(j,0,s/e) {
auto t = upper_bound(g[a[i]].begin(),g[a[i]].end(),dp[j]);
if (t==g[a[i]].end()) continue;
dp[j+1] = min(dp[j+1], *t);
if (dp[j+1]+i+e*(j+1)<=s) ans=max(ans,j+1);
}
printf("%d\n", ans);
}