제출 #7453

#제출 시각아이디문제언어결과실행 시간메모리
7453conankun수열 (APIO14_sequence)C++98
0 / 100
0 ms131072 KiB
#include <stdio.h> int arr[1111111]; int dp[211][111111]; int bt[211][111111]; int sum[1111111]; int seq[111111]; int n,K; int main() { scanf("%d%d",&n,&K); int i,j,k; for(i=1;i<=n;i++) { scanf("%d",&sum[i]); sum[i] += sum[i-1]; } dp[1][1]=sum[1] * (sum[n]-sum[1]); int ans=-1,kk=n; for(k=1;k<=K;k++){ for(i=1;i<=n;i++){ for(j=0;j<i;j++) { if(dp[k-1][j] + (sum[i]-sum[j])*(sum[n]-sum[i]) > dp[k][i]){ dp[k][i] = dp[k-1][j] + (sum[i]-sum[j])*(sum[n]-sum[i]); bt[k][i] = j; if(k==K && dp[k][i] >ans){ ans = dp[k][i]; kk=i; } } } } } printf("%d\n",ans); int a=kk; seq[K+1]=kk; for(k=K;k>=1;k--){ seq[k]=bt[k][a]; a = bt[k][a]; } for(i=2;i<=K+1;i++) printf("%d ",seq[i]); }
#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...