乌龟棋

乌龟棋

https://ac.nowcoder.com/acm/problem/16590

和之前的着色方案差不多
用dp[a][b][c][d] ,a表示1的卡片,b表示2的卡片,c表示3的卡片,d表示4的卡片
然后直接搜索就行了

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#define ll long long
#define pi 3.1415927
#define inf 0x3f3f3f3f
#define mod 1000000007
using namespace std;
#define _int __int128_t
int n,m,dp[45][45][45][45],aa[1005],bb[6];
int dfs(int a, int b, int c, int d)
{
    if(a+b+c+d==0)
        return aa[n];
    if(dp[a][b][c][d])
        return dp[a][b][c][d];
    int l=bb[1]-a+2*(bb[2]-b)+3*(bb[3]-c)+4*(bb[4]-d)+1;
    int ans=0;
    if(a) ans =max(ans,aa[l]+dfs(a-1,b,c,d));
    if(b) ans =max(ans,aa[l]+dfs(a,b-1,c,d));
    if(c) ans =max(ans,aa[l]+dfs(a,b,c-1,d));
    if(d) ans =max(ans,aa[l]+dfs(a,b,c,d-1));
    return dp[a][b][c][d]= ans;
}
int main ()
{
    int T,i,t,j,k,p,sum=0;
    cin>>n>>m;
    for(i=1;i<=n;++i)
        cin>>aa[i];
    for(i=1;i<=m;++i){
        cin>>p;
        bb[p]++;
    }
    sum=dfs(bb[1],bb[2],bb[3],bb[4]);
    cout<<sum<<endl;

    return 0;
}
全部评论

相关推荐

不愿透露姓名的神秘牛友
昨天 12:11
我最近都有点不想活了,天天早10晚11的,还问我爱不爱她目前的状态别说爱谁了,没扇谁就不错了。是不是大家都是一进节子,只有工作没有爱情了
AzureSkies:在字节的时候找的就是字节的,飞书太适合恋爱人士了,能看到是不是已读,是不是在会议中。简直冥婚好伴侣
投递字节跳动等公司9个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务