题意:
思路:
#include <cstdio>
#include <algorithm>
using namespace std;
const int M = 45;
const int N = 355;
int dp[M][M][M][M];
int w[N];
int n,m;
int num[5];
int main(){
scanf("%d%d",&n,&m);
for(int i = 0;i < n;i++) scanf("%d",w+i);
for(int i = 0;i < m;i++){
int x;scanf("%d",&x);
num[x]++;
}
for(int a = 0;a <= num[1];a++){
for(int b = 0;b <= num[2];b++){
for(int c = 0;c <= num[3];c++){
for(int d = 0;d <= num[4];d++){
int score = w[a+2*b+3*c+4*d];
int &v = dp[a][b][c][d];
v = score;
if(a) v = max(v,dp[a-1][b][c][d]+score);
if(b) v = max(v,dp[a][b-1][c][d]+score);
if(c) v = max(v,dp[a][b][c-1][d]+score);
if(d) v = max(v,dp[a][b][c][d-1]+score);
}
}
}
}
printf("%d\n",dp[num[1]][num[2]][num[3]][num[4]]);
return 0;
}