90pts 10 TLE 求卡
  • 板块P1725 琪露诺
  • 楼主fjh0531
  • 当前回复3
  • 已保存回复3
  • 发布时间2023/12/15 13:02
  • 上次更新2023/12/15 17:12:41
查看原帖
90pts 10 TLE 求卡
952663
fjh0531楼主2023/12/15 13:02
#include<bits/stdc++.h>
using namespace std;
int ans;
inline unsigned int read()
{
    int f=1,x=0;
    char a=getchar();
    while(a>'9'||a<'0')
    {
        if(a=='-') f=-1;
        a=getchar();
    }
    while(a<='9'&&a>='0')
    {
        x=x*10+a-'0';
        a=getchar();
    }
    return f*x;
}
inline void write(int x)
{
    if(x<0)
    {
        putchar('-');
        x=-x;
    }
    if(x>9)
    {
        write(x/10);
    }
    putchar(x%10+'0');
    return;
}
const int maxn=2e5+1;
int N,L,R;
int A[maxn];
int dp[maxn];
bool q[maxn];

int main(){
    N=read(),L=read(),R=read();
    ans=-INT_MAX;
    for(int i=0;i<=N;i++) A[i]=read();
    q[0]=true;
    for(int i=L;i<=N;i++){
        dp[i]=-INT_MAX+1;
        for(int j=L;j<=R;j++) if(i>=j&&q[i-j]==true) dp[i]=max(dp[i],dp[i-j]),q[i]=true;
        dp[i]+=A[i];
    }
    for(int i=N;i>N-R;i--) if(q[i]==true) ans=max(ans,dp[i]);
    write(ans);
}

只是说有没有可能,有没有那么一种可能,这个代码略微优化就能过

2023/12/15 13:02
加载中...