乌龟棋

#include<algorithm>
#include <cstdio>
using namespace std;
const int N = 365;
int a[N], b[10];
int f[41][41][41][41];
int main()
{
    int n, m;
    cin >>n >>m;
    for(int i = 0; i < n; i ++)cin >>a[i];// a[i]下标要从0开始
    
    for (int i = 0; i < m; i ++ )
    {
        int t;
        scanf("%d", &t);
        b[t] ++ ;
    }
    
    for(int i = 0; i <= b[1]; i ++)
        for(int j = 0; j <= b[2]; j ++)
            for(int k = 0; k <= b[3]; k ++)
                for(int l = 0; l <= b[4]; l ++)
                {
                    int cnt = a[i * 1 + j * 2 + k * 3 + l * 4];
                    int &v = f[i][j][k][l];
                    v = cnt;
                    if(i)v = max(v, f[i - 1][j][k][l] + cnt);
                    if(j)v = max(v, f[i][j - 1][k][l] + cnt);
                    if(k)v = max(v, f[i][j][k - 1][l] + cnt);
                    if(l)v = max(v, f[i][j][k][l - 1] + cnt);
                }
    printf("%d\n", f[b[1]][b[2]][b[3]][b[4]]);
    return 0;
}
全部评论

相关推荐

牛客771574427号:恭喜你,华杰
点赞 评论 收藏
分享
评论
1
收藏
分享
牛客网
牛客企业服务