不开O2 92,开了4 分求助
查看原帖
不开O2 92,开了4 分求助
414386
Isshiki·Iroha楼主2024/1/27 11:44
#include<bits/stdc++.h>
#define ll long long
using namespace std;
namespace Mashiro {
    char buf[1<<18],*p1=buf,*p2=buf;
    inline int getc() {
        return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<18,stdin),p1==p2)?EOF:*p1++;
    }
    template<typename T>inline void read(T& x) {
        x=0;int f=1;
        char ch=getc();
        while(!isdigit(ch)){if(ch=='-')f=~f+1;ch=getc();}
        while (isdigit (ch)) {x=(x<<3)+(x<<1)+(ch^48);ch=getc();}
        x*=f;
    }      
    template <typename T,typename... Args> inline void read(T& x, Args&... args) {
        read(x);
        read(args...);
    }
    char buffer[1<<18];int p11=-1;const int p22=(1<<18)-1;
    inline void flush() {fwrite(buffer,1,p11+1,stdout),p11=-1;}
    inline void putc(const char &x) {if (p11==p22) flush();buffer[++p11]=x;}
    template<typename T>inline void write(T x) {
        static int buf[40],top=0;
        if(x<0)putc('-'),x=~x+1;
        while(x)buf[++top]=x%10,x/=10;
        if(top==0)buf[++top]=0;
        while (top) putc(buf[top--]^48);
        putc(' ');
        flush();
     }
     template <typename T,typename... Args> inline void write(T x, Args... args) {
         write(x);
         write(args...);
     }
}
using namespace Mashiro;
const int maxn=2005;
int a[maxn][maxn],c[maxn],h[maxn][maxn];
ll dp[maxn][maxn][2];
//第k个机器人第i天走到j点的最大值
int n,m,p;
ll calc(int i,int j,int k){
    return h[i-1][j-1]-h[i-1-k][j-1-k];
}
int main() {
    read(n,m,p);
    m++;
    for(int i(1);i<=n;++i){
        for(int j(1);j<m;++j){
            read(a[i][j]);
        }
    }
    for(int i(1);i<=n;i++){
        for(int j=1;j<m;j++){
            h[j][i]=h[j-1][i-1]+a[i][j];
        }
    }
    memset(dp,~0x3f,sizeof dp);
    // for(int i(1);i<=n;++i){
    //     for(int j(1);j<=m;++j){
    //         write(h[i][j]);
    //     }
    //     putc('\n');
    // }
    // Pause
    for(int i(1);i<=n;++i){
        read(c[i]);
    }
    for(int i=1;i<=n;i++)
        dp[1][i][0]=-c[i];
    
    for(int i(2);i<=m;++i){
        for(int j(1);j<=n;++j){
            for(int k(1);k<=min(i,p);++k){
                if(j>k)
                    dp[i][j][1]=max(dp[i][j][1],dp[i-k][j-k][0]+calc(i,j,k));
                else if(i>j)
                    dp[i][j][1]=max(dp[i][j][1],dp[i-k][n+j-k][0]+calc(i-j+1,n+1,k-j+1)+calc(i,j,j-1));
            }

        }
        for(int j(1);j<=n;++j){
            for(int k(1);k<=n;++k){
                if(k==j) continue;
                dp[i][j][0]=max(dp[i][j][0],dp[i][k][1]-c[j]);
            }
        }
    }
    ll ans=-1e18;
    for(int i(1);i<=n;++i)ans=max(ans,dp[m][i][1]);
    write(ans);
    return 0;
}

2024/1/27 11:44
加载中...