求助,用了DP 为啥TLE?
查看原帖
求助,用了DP 为啥TLE?
332578
emoheizi楼主2020/6/10 18:45

代码如下:

#define MAX_VAL 1000+5
#include <bits/stdc++.h>
using namespace std;
int n;
int curs[MAX_VAL];

inline void redn(int& res){
    char ch=getchar();int cof = 1; res=0;
    while(ch>'9'||ch<'0') if(ch=='-') cof = -1,ch=getchar();
    while(ch>='0'&&ch<='9') res = res*10 + (ch-'0'),ch=getchar();;
    res *= cof;
}

int main(int arg,char **argv){
    redn(n);
    int temp;
    for(int i=n;i>0;i--)
        for(int j=i;j<=n;j++) redn(temp),curs[j] = max(curs[j],curs[j+1]) + temp;
    int ans = 0;
    for(int i=1;i<=n;i++)
        ans = max(ans,curs[i]);
    cout<<ans;
    return 0;
}
2020/6/10 18:45
加载中...