제출 #33646

#제출 시각아이디문제언어결과실행 시간메모리
33646dqhungdl수열 (APIO14_sequence)C++14
50 / 100
413 ms6176 KiB
#include <bits/stdc++.h> using namespace std; int64_t n,k,a[100005],f[1005][205],Trace[1005][205]; void Sub1() { for(int64_t i=1;i<=n;i++) { cin>>a[i]; a[i]+=a[i-1]; } for(int64_t i=0;i<=n;i++) for(int64_t j=0;j<=k;j++) f[i][j]=-1; f[0][0]=0; for(int64_t i=1;i<=n;i++) for(int64_t j=1;j<=k;j++) for(int64_t t=1;t<=i;t++) if(f[t-1][j-1]!=-1&&f[i][j]<f[t-1][j-1]+(a[i]-a[t-1])*a[t-1]) { f[i][j]=f[t-1][j-1]+(a[i]-a[t-1])*a[t-1]; Trace[i][j]=t-1; } cout<<f[n][k]<<"\n"; while(k>1) { cout<<Trace[n][k]<<' '; n=Trace[n][k]; k--; } } int main() { ios_base::sync_with_stdio(false); //freopen("TEST.INP","r",stdin); cin>>n>>k; k++; if(n<=1000) Sub1(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...