dp..dp的时候不能设f[N][x1][x2][x3][x4],会T,要把N省略,然后通过1/2/3/4牌的数量来算已经走到哪一个了
#include<bits/stdc++.h>
#define pa pair<int,int>
#define ll long long
using namespace std;
const int maxn=,maxm=; inline ll rd(){
ll x=;char c=getchar();int neg=;
while(c<''||c>''){if(c=='-') neg=-;c=getchar();}
while(c>=''&&c<='') x=x*+c-'',c=getchar();
return x*neg;
} int N,M,m[];
int f[maxm][maxm][maxm][maxm];
bool flag[][][maxm];
int v[maxn]; inline void sm(int &a,int b){
if(b>a) a=b;
} int main(){
int i,j,k;
N=rd(),M=rd();
for(i=;i<N;i++) v[i]=rd();
for(i=;i<=M;i++) m[rd()]++;
f[][][][]=v[];
for(int x1=;x1<=m[];x1++){
for(int x2=;x2<=m[];x2++){
for(int x3=;x3<=m[];x3++){
for(int x4=;x4<=m[];x4++){
int now=f[x1][x2][x3][x4],pos=x1*+x2*+x3*+x4*;
if(x1<m[]) sm(f[x1+][x2][x3][x4],now+v[pos+]);
if(x2<m[]) sm(f[x1][x2+][x3][x4],now+v[pos+]);
if(x3<m[]) sm(f[x1][x2][x3+][x4],now+v[pos+]);
if(x4<m[]) sm(f[x1][x2][x3][x4+],now+v[pos+]);
}
}
}
}printf("%d\n",f[m[]][m[]][m[]][m[]]);
return ;
}