Guest User

Untitled

a guest
Jan 18th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3.  
  4. int value[1001];
  5. int DP[1001];
  6.  
  7. int main()
  8. {
  9. int max = 0, N;
  10.  
  11. scanf("%d", &N);
  12.  
  13. for (int a = 1; a <= N; a++) {
  14. scanf("%d", &value[a]);
  15. DP[a] = value[a];
  16. }
  17.  
  18. for (int a = 2; a <= N; a++) {
  19. for (int b = 1; b <= a; b++) {
  20. max = DP[b] + value[a - b];
  21. if (max > DP[a])
  22. DP[a] = max;
  23. }
  24. }
  25.  
  26. printf("%d\n", DP[N]);
  27. return 0;
  28. }
Add Comment
Please, Sign In to add comment