P1541 乌龟棋

P1541 乌龟棋

 

水题,思维海星。

#include<bits/stdc++.h>
using namespace std;

const int maxn=355;
int a[maxn];
int book[5];
int f[45][45][45][45];

int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1; i<=n; i++)
        scanf("%d",&a[i]);
    for(int i=1; i<=m; i++)
    {
        int t;
        scanf("%d",&t);
        book[t]++;
    }
    for(int i=0;i<=book[1];i++)
        for(int j=0;j<=book[2];j++)
            for(int k=0;k<=book[3];k++)
                for(int l=0;l<=book[4];l++)
                {
                    if(i!=0) f[i][j][k][l]=max(f[i][j][k][l],f[i-1][j][k][l]+a[i+j*2+k*3+l*4+1]);
                    if(j!=0) f[i][j][k][l]=max(f[i][j][k][l],f[i][j-1][k][l]+a[i+j*2+k*3+l*4+1]);
                    if(k!=0) f[i][j][k][l]=max(f[i][j][k][l],f[i][j][k-1][l]+a[i+j*2+k*3+l*4+1]);
                    if(l!=0) f[i][j][k][l]=max(f[i][j][k][l],f[i][j][k][l-1]+a[i+j*2+k*3+l*4+1]);
                }
    printf("%d",f[book[1]][book[2]][book[3]][book[4]]+a[1]);
}

 

posted @ 2019-07-16 21:32  paranoid。  阅读(127)  评论(0编辑  收藏  举报