Submission #16823

#TimeUsernameProblemLanguageResultExecution timeMemory
16823kdh9949Split the sequence (APIO14_sequence)C++98
0 / 100
0 ms17568 KiB
#include<stdio.h> #include<algorithm> using namespace std; int n,k,mxi; int a[100010]; int sum[100010]; int dp[10001][201]; int prev[10001][201]; void init_partsum(){ for(int i=1;i<=n;i++)sum[i]=sum[i-1]+a[i]; } int partsum(int s,int e){ return (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("%d\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...