답안 #135192

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
135192 2019-07-23T19:27:56 Z pedro_sponchiado 수열 (APIO14_sequence) C++17
0 / 100
10 ms 5112 KB
#include<bits/stdc++.h>
using namespace std;
const int INF=100000000;
const int maxn=1010;
const int maxk=210;
int n, d;
int a[maxn];

 int parc[maxn], parc_2[maxn];
int S_2[maxn][maxn];
//long long int S_2(int i, int j){ 
	
 int dp[maxn][maxk];

int main(){
	scanf("%d %d", &n, &d);
	for(int i=1; i<=n; i++){
		scanf("%d", &a[i]);
		parc[i]=parc[i-1]+a[i];
		parc_2[i]=parc_2[i-1]+a[i]*a[i];
	}	
		
	for(int i=1; i<=n; i++){
		for(int k=i; k<=n; k++){
			S_2[i][k]= (parc[k]-parc[i-1])*(parc[k]-parc[i-1])-parc_2[k]+parc_2[i-1];
		}
	}
	
	for(int i=1; i<=n; i++) dp[i][0]=S_2[1][i];
	
	for(int k=1; k<=d; k++){
		for(int i=1; i<=n; i++){
			dp[i][k]=INF;
			if(k>=i)continue;
			
			for(int l=1; l<i; l++){
				dp[i][k]=min(dp[i][k], dp[l][k-1]+S_2[l+1][i]);	
			}
			
		//	printf("dp[%d][%d]=%lld\n", i, k, dp[i][k]);
		}
		 
	}
	
	printf("%d\n", (S_2[1][n]-dp[n][d])/2); 
	return 0;	
}

Compilation message

sequence.cpp: In function 'int main()':
sequence.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &d);
  ~~~~~^~~~~~~~~~~~~~~~~
sequence.cpp:18:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
   ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 632 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 1272 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 5112 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 380 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -