最后一个点求条,悬一关
查看原帖
最后一个点求条,悬一关
770431
GavinCQTD楼主2024/10/13 15:59
/******************************
  @GavinCQTD / %$Time$%
  "%$Problem$%" From %$Contest$%
  # %$URL$%
  %$TimeL$% ms / %$MemoryL$% MB
******************************/
/* We all make choices, but in the end our choices make us. */

// #pragma GCC optimize(1,2,3,"Ofast","inline")

#include <iostream>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <assert.h>
using namespace std;
inline void pass(){return;}
#define endl "\n"
#define mp(a,b) make_pair(a,b)
#define ct(a) while(!a.empty()) a.pop()
#define cdb cerr<<"Debug: "
#define cwn cerr<<"Warn: "
#define debug(x) cerr<<"In Line "<<__LINE__<<": "<<#x<<" = "<<x<<"\n"
#define sp(a) <<fixed<<setprecision(a)
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#define ll long long
#define ull unsigned long long
#define ld long double
// #define int ll
// #define debug

int t,n,m,p,sc[1005][1005],nc[1005],sum,f[1005];

inline int getStart(int j,int k){return (j-k<=0)?(n+(j-k)%n):(j-k);}

void solve(int testID){
    memset(f,-2E9,sizeof(f));
    cin >> n >> m >> p;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++) cin>>sc[i][j];
    }
    for(int i=1;i<=n;i++) cin>>nc[i];
    // for(int i=1;i<=m;i++){
    //     for(int j=0;j<n;j++) sum[i][j]=sum[i-1][(j-1+n)%n]+sc[i][j];
    // }
    for(int i=1;i<=m;i++){
        for(int j=1;j<=n;j++){
            sum = 0;
            for(int k=1;k<=min(p,i);k++){
                sum += sc[getStart(j,k)][i-k+1];
                f[i] = max(f[i],f[i-k]+sum-nc[getStart(j,k)]);
            }
        }
    }
    cout << f[m];
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    // freopen(".in", "r", stdin);
    // freopen(".out", "w", stdout);
    // freopen("PublicDebug.debug", "w", stderr);

    // cout sp();
    // cerr sp();

    t = 1;
    // cin >> t;

    for(int ran=0;ran<t;ran++) solve(ran);

    fflush(stdout);
    return 0;
}

输出 6262,讨论区同样的问题都是没初始化成 -INF 导致的,我初始化了还是 WA。

2024/10/13 15:59
加载中...