2 条题解

  • 1
    @ 2022-08-04 15:15:54

    来自于yejun的解题链接
    /*

    /
    #define method_1
    #ifdef method_1
    /

    */
    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cmath>
    #include<set>
    #include<map>
    #include<queue>
    #include<stack>
    #include<vector>
    #include<cstring>
    #include<cstdlib>
    #include<iomanip>
    #define D(x) cout<<#x<<" = "<<x<<" "
    #define E cout<<endl
    using namespace std;
    typedef long long ll;
    typedef pair<int,int>pii;
    const int maxn=350+5;
    const int maxm=40+5;
    const int INF=0x3f3f3f3f;
    int d[maxm][maxm][maxm][maxm]={0},cnt1=0,cnt2=0,cnt3=0,cnt4=0,n,m,a[maxn],x;
    int main() {
    ios::sync_with_stdio(false);
    //freopen("乌龟棋.in","r",stdin);
    cin>>n>>m;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=m;i++){
    cin>>x;
    if(x==1) cnt1++;
    if(x==2) cnt2++;
    if(x==3) cnt3++;
    if(x==4) cnt4++;
    }
    d[0][0][0][0]=a[1];
    for(int i=0;i<=cnt1;i++){
    for(int j=0;j<=cnt2;j++){
    for(int k=0;k<=cnt3;k++){
    for(int l=0;l<=cnt4;l++){
    int &temp=d[i][j][k][l];
    int v=a[i+2*j+3*k+4*l+1];
    if(i) temp=max(temp,d[i-1][j][k][l]+v);
    if(j) temp=max(temp,d[i][j-1][k][l]+v);
    if(k) temp=max(temp,d[i][j][k-1][l]+v);
    if(l) temp=max(temp,d[i][j][k][l-1]+v);
    }
    }
    }
    }
    cout<<d[cnt1][cnt2][cnt3][cnt4];
    return 0;
    }
    #endif
    #ifdef method_2
    /*

    */

    #endif
    #ifdef method_3
    /*

    */

    #endif

  • 0
    @ 2019-06-06 15:52:52
  • 1

信息

ID
1076
难度
5
分类
动态规划 点击显示
标签
递交数
78
已通过
30
通过率
38%
上传者