怎么优化呀,我21-25全TLE

P5638 【CSGRound2】光骓者的荣耀

Where is your CODE?
by Failure_Creator @ 2022-07-03 19:37:47


```cpp #include<iostream> #include<cstdio> #include<cmath> using namespace std; long long a[1000008],n,k,MIN=900000000000000,map[1000008][2]; void f(long long p,long long q,int y){ if(p>=n){ MIN=min(MIN,q); return; } if(p<1){ p=1; } if(q>MIN){ return; } if(y==1){ f(p+k,q,0); } f(p+1,q+a[p],y); } int main(){ scanf("%lld%lld",&n,&k); for(int i=1;i<n;i++){ scanf("%lld",&a[i]); } f(1,0,1); printf("%lld",MIN); return 0; } ``` 谢谢
by Gnasvl @ 2022-07-04 19:20:35


@[Lvsang](/user/590596) 用前缀和啊
by Happy_Orca @ 2022-07-06 17:47:23


啊,我没看标签,谢谢
by Gnasvl @ 2022-07-06 18:14:40


|