• 【dp】P1541 乌龟棋


    链接:

    https://www.luogu.org/problemnew/show/P1541

    【思路】:

    用f[a][b][c][d]表示,第一张卡用a张,第二张卡用b张..........然后就盘就ok了

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cmath>
    #include<queue>
    #include<stack>
    #include<vector>
    #include<map>
    #include<string>
    #include<cstring>
    using namespace std;
    const int maxn=999999999;
    const int minn=-999999999;
    inline int read() {
        char c = getchar();
        int x = 0, f = 1;
        while(c < '0' || c > '9') {
            if(c == '-') f = -1;
            c = getchar();
        }
        while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
        return x * f;
    }
    int n,m,a[355],f[41][41][41][41],s[305],js[5],b;
    int main() {
        cin>>n>>m;
        for(int i=1; i<=n; ++i) {
            a[i]=read();
        }
        for(int i=1; i<=m; ++i) {
            cin>>b;
            js[b]++;
        }
         f[0][0][0][0]=a[1];
        for(int i=0; i<=js[1]; ++i) {
            for(int j=0; j<=js[2]; ++j) {
                for(int k=0; k<=js[3]; ++k) {
                    for(int l=0; l<=js[4]; ++l) {
                        int place=1+i*1+j*2+k*3+l*4;
                        if(i!=0) {
                            f[i][j][k][l]=max(f[i][j][k][l],f[i-1][j][k][l]+a[place]);
                        }
                        if(j!=0) {
                            f[i][j][k][l]=max(f[i][j][k][l],f[i][j-1][k][l]+a[place]);
                        }
                        if(k!=0) {
                            f[i][j][k][l]=max(f[i][j][k][l],f[i][j][k-1][l]+a[place]);
                        }
                        if(l!=0) {
                            f[i][j][k][l]=max(f[i][j][k][l],f[i][j][k][l-1]+a[place]);
                        }
                    }
                }
            }
        }
        cout<<f[js[1]][js[2]][js[3]][js[4]];
        return 0;
    }
  • 相关阅读:
    codeforces 368B
    codeforces 651A
    codeforces 651B
    codeforces 732B
    codeforces 313B
    codeforces 550A
    codeforces 498B
    Linux C/C++基础——内存分区
    Linux C/C++基础——变量作用域
    Linux C/C++基础——Windows远程登录Linux
  • 原文地址:https://www.cnblogs.com/pyyyyyy/p/10797800.html
Copyright © 2020-2023  润新知