Hax4Us

Dp2

Jun 21st, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.58 KB | None | 0 0
  1. #include <stdio.h>
  2. #define MAX( a, b ) ( ( a > b) ? a : b )                        
  3.  
  4. void main(void) {
  5. const int n =6;
  6. int a[n]={5,1,2,3,99,115};
  7. int sum_table[2] = {a[0], a[1]};                                          for(int i = 2; i < n; i++){                                               int tmp = sum_table[1];                                           sum_table[1] = sum_table[0] + a[i];
  8.                         sum_table[0] = MAX(sum_table[0], tmp);
  9.                        
  10.                 }
  11.         int ans = MAX(sum_table[0], sum_table[1]);
  12.         printf("%d",ans);
  13. }
Add Comment
Please, Sign In to add comment