济南icpc2022J. Skills

J. Skills


#include<bits/stdc++.h>
#define ll long long 
using namespace std;
const int N = 1e3+5;
ll dp[2][4][205][205],a[1005][4];
void solve(){
    ll ans = 0;
    memset(dp,0,sizeof(dp));
    memset(a,0,sizeof(a));
    ll n;cin >> n;
    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= 3;j++){
            cin >> a[i][j];
        }
    }


    for(int i = 0;i < n;i++){
        // dp[(i+1)%2][1][0][0] = dp[i%2][1][0][0] + a[(i+1)][1];
        // dp[(i+1)%2][2][0][0] = dp[i%2][2][0][0] + a[(i+1)][2];
        // dp[(i+1)%2][3][0][0] = dp[i%2][3][0][0] + a[(i+1)][3];
        //1
        for(int x = 0;x <= i&&x <= 200;x++){  // x  2  y  3 
            for(int y = 0;y <= i&&y <= 200;y++){
                if(x!=0&&y!=0){
                    dp[(i+1)%2][1][x+1][y+1] = max(dp[(i+1)%2][1][x+1][y+1],a[(i+1)][1] + dp[i%2][1][x][y] - x - y);
                    dp[(i+1)%2][2][2][y+1] = max(dp[(i+1)%2][2][2][y+1],a[(i+1)][2] + dp[i%2][1][x][y] - 1 - y);
                    dp[(i+1)%2][3][2][x+1] = max(dp[(i+1)%2][3][2][x+1],a[(i+1)][3] + dp[i%2][1][x][y] - 1 - x);
                }else if(x==0&&y!=0){
                    dp[(i+1)%2][1][x][y+1] = max(dp[(i+1)%2][1][x][y+1],a[(i+1)][1] + dp[i%2][1][x][y] - x - y);
                    dp[(i+1)%2][2][2][y+1] = max(dp[(i+1)%2][2][2][y+1],a[(i+1)][2] + dp[i%2][1][x][y] - 1 - y);
                    dp[(i+1)%2][3][2][x] = max(dp[(i+1)%2][3][2][x],a[(i+1)][3] + dp[i%2][1][x][y] - 1 - x);
                }else if(x!=0&&y==0){
                    dp[(i+1)%2][1][x+1][y] = max(dp[(i+1)%2][1][x+1][y],a[(i+1)][1] + dp[i%2][1][x][y] - x - y);
                    dp[(i+1)%2][2][2][y] = max(dp[(i+1)%2][2][2][y],a[(i+1)][2] + dp[i%2][1][x][y] - 1 - y);
                    dp[(i+1)%2][3][2][x+1] = max(dp[(i+1)%2][3][2][x+1],a[(i+1)][3] + dp[i%2][1][x][y] - 1 - x);
                }else if(x==0&&y==0){
                    dp[(i+1)%2][1][x][y] = max(dp[(i+1)%2][1][x][y],a[(i+1)][1] + dp[i%2][1][x][y] - x - y);
                    dp[(i+1)%2][2][2][y] = max(dp[(i+1)%2][2][2][y],a[(i+1)][2] + dp[i%2][1][x][y] - 1 - y);
                    dp[(i+1)%2][3][2][x] = max(dp[(i+1)%2][3][2][x],a[(i+1)][3] + dp[i%2][1][x][y] - 1 - x);
                }
                
            }
        }
        //2
        for(int x = 0;x <= i&&x <= 200;x++){  // x  1  y  3 
            for(int y = 0;y <= i&&y <= 200;y++){
                if(x!=0&&y!=0){
                    dp[(i+1)%2][2][x+1][y+1] = max(dp[(i+1)%2][2][x+1][y+1],a[(i+1)][2] + dp[i%2][2][x][y] - x - y);
                    dp[(i+1)%2][1][2][y+1] = max(dp[(i+1)%2][1][2][y+1],a[(i+1)][1] + dp[i%2][2][x][y] - 1 - y);
                    dp[(i+1)%2][3][x+1][2] = max(dp[(i+1)%2][3][x+1][2],a[(i+1)][3] + dp[i%2][2][x][y] - 1 - x);
                }else if(x==0&&y!=0){
                    dp[(i+1)%2][2][x][y+1] = max(dp[(i+1)%2][2][x][y+1],a[(i+1)][2] + dp[i%2][2][x][y] - x - y);
                    dp[(i+1)%2][1][2][y+1] = max(dp[(i+1)%2][1][2][y+1],a[(i+1)][1] + dp[i%2][2][x][y] - 1 - y);
                    dp[(i+1)%2][3][x][2] = max(dp[(i+1)%2][3][x][2],a[(i+1)][3] + dp[i%2][2][x][y] - 1 - x);
                }else if(x!=0&&y==0){
                    dp[(i+1)%2][2][x+1][y] = max(dp[(i+1)%2][2][x+1][y],a[(i+1)][2] + dp[i%2][2][x][y] - x - y);
                    dp[(i+1)%2][1][2][y] = max(dp[(i+1)%2][1][2][y],a[(i+1)][1] + dp[i%2][2][x][y] - 1 - y);
                    dp[(i+1)%2][3][x+1][2] = max(dp[(i+1)%2][3][x+1][2],a[(i+1)][3] + dp[i%2][2][x][y] - 1 - x);
                }else if(x==0&&y==0){
                    dp[(i+1)%2][2][x][y] = max(dp[(i+1)%2][2][x][y],a[(i+1)][2] + dp[i%2][2][x][y] - x - y);
                    dp[(i+1)%2][1][2][y] = max(dp[(i+1)%2][1][2][y],a[(i+1)][1] + dp[i%2][2][x][y] - 1 - y);
                    dp[(i+1)%2][3][x][2] = max(dp[(i+1)%2][3][x][2],a[(i+1)][3] + dp[i%2][2][x][y] - 1 - x);
                }
                
                
            }
        }
        //3
        for(int x = 0;x <= i&&x <= 200;x++){  // x  1  y  2
            for(int y = 0;y <= i&&y <= 200;y++){
                if(x!=0&&y!=0){
                    dp[(i+1)%2][3][x+1][y+1] = max(dp[(i+1)%2][3][x+1][y+1],a[(i+1)][3] + dp[i%2][3][x][y] - x - y);
                    dp[(i+1)%2][2][x+1][2] = max(dp[(i+1)%2][2][x+1][2],a[(i+1)][2] + dp[i%2][3][x][y] - 1 - x);
                    dp[(i+1)%2][1][y+1][2] = max(dp[(i+1)%2][1][y+1][2],a[(i+1)][1] + dp[i%2][3][x][y] - 1 - y);
                }else if(x==0&&y!=0){
                    dp[(i+1)%2][3][x][y+1] = max(dp[(i+1)%2][3][x][y+1],a[(i+1)][3] + dp[i%2][3][x][y] - x - y);
                    dp[(i+1)%2][2][x][2] = max(dp[(i+1)%2][2][x][2],a[i+1][2] + dp[i%2][3][x][y] - 1 - x);
                    dp[(i+1)%2][1][y+1][2] = max(dp[(i+1)%2][1][y+1][2],a[(i+1)][1] + dp[i%2][3][x][y] - 1 - y);
                }else if(x!=0&&y==0){
                    dp[(i+1)%2][3][x+1][y] = max(dp[(i+1)%2][3][x+1][y],a[(i+1)][3] + dp[i%2][3][x][y] - x - y);
                    dp[(i+1)%2][2][x+1][2] = max(dp[(i+1)%2][2][x+1][2],a[(i+1)][2] + dp[i%2][3][x][y] - 1 - x);
                    dp[(i+1)%2][1][y][2] = max(dp[(i+1)%2][1][y][2],a[(i+1)][1] + dp[i%2][3][x][y] - 1 - y);
                }else if(x==0&&y==0){
                    dp[(i+1)%2][3][x][y] = max(dp[(i+1)%2][3][x][y],a[(i+1)][3] + dp[i%2][3][x][y] - x - y);
                    dp[(i+1)%2][2][x][2] = max(dp[(i+1)%2][2][x][2],a[(i+1)][2] + dp[i%2][3][x][y] - 1 - x);
                    dp[(i+1)%2][1][y][2] = max(dp[(i+1)%2][1][y][2],a[(i+1)][1] + dp[i%2][3][x][y] - 1 - y);
                }
                
            }
        }

    }
    // cout<<dp[n][1][2][3] << "?";
    for(int j = 1;j <= 3;j++){
        for(int x = 0;x <= 200;x++){
            for(int y = 0; y <= 200;y++ ){
                ans = max(ans , dp[(n)%2][j][x][y]);
            }
        }
    }
    cout << ans << "\n";

}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin>>t;
    while(t--){
        solve();
    }
}

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值