제출 #16821

#제출 시각아이디문제언어결과실행 시간메모리
16821kdh9949수열 (APIO14_sequence)C++98
0 / 100
0 ms131072 KiB
#include<stdio.h> #include<algorithm> using namespace std; int n,k,mxi; int a[100010]; int sum[100010]; long long dp[100010][201]; int prev[100010][201]; void init_partsum(){ for(int i=1;i<=n;i++)sum[i]=sum[i-1]+a[i]; } long long partsum(int s,int e){ return (long long)(sum[e]-sum[s-1]); } int main() { scanf("%d%d",&n,&k); for(int i=1;i<=n;i++)scanf("%d",a+i); init_partsum(); for(int i=1;i<n;i++){ for(int j=1;j<=k;j++){ if(i<j)break; for(int q=j-1;q<i;q++){ if(dp[i][j]<dp[q][j-1]+partsum(q+1,i)*partsum(i+1,n)){ dp[i][j]=dp[q][j-1]+partsum(q+1,i)*partsum(i+1,n); prev[i][j]=q; } } } } mxi=k+1; for(int i=k+2;i<n;i++)if(dp[i][k]>dp[mxi][k])mxi=i; printf("%lld\n%d",dp[mxi][k],mxi); for(int i=k;i>1;i--){ mxi=prev[mxi][i]; printf(" %d",mxi); } }
#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...