Guest User

Untitled

a guest
Apr 19th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. #include <cstdio>
  2. #include <memory.h>
  3. using namespace std;
  4.  
  5. long Niz[200],Suma[200],Ig[200][200],N,i,j;
  6.  
  7. long mini(long x,long y){
  8. if (x>y) x=y;
  9. return x;
  10. }
  11.  
  12. long Opt(long l,long r){
  13. long rezultat;
  14. if (Ig[l][r]!=-1) return Ig[l][r];
  15. if (l==r) rezultat=Niz[l]; else rezultat = Suma[r] - Suma[l-1] - mini(Opt(l+1,r),Opt(l,r-1));
  16. Ig[l][r]=rezultat;
  17. return rezultat;
  18. }
  19.  
  20. int main(){
  21. scanf("%ld",&N);
  22. memset(Ig,255,160000);
  23. Suma[0]=0;
  24. for (i=1; i<=N; i++) {
  25. scanf("%ld",&Niz[i]);
  26. Suma[i]=Suma[i-1]+Niz[i];
  27. }
  28. printf("%ld",Opt(1,N));
  29. return 0;
  30. }
Add Comment
Please, Sign In to add comment