Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <memory.h>
- using namespace std;
- long Niz[200],Suma[200],Ig[200][200],N,i,j;
- long mini(long x,long y){
- if (x>y) x=y;
- return x;
- }
- long Opt(long l,long r){
- long rezultat;
- if (Ig[l][r]!=-1) return Ig[l][r];
- if (l==r) rezultat=Niz[l]; else rezultat = Suma[r] - Suma[l-1] - mini(Opt(l+1,r),Opt(l,r-1));
- Ig[l][r]=rezultat;
- return rezultat;
- }
- int main(){
- scanf("%ld",&N);
- memset(Ig,255,160000);
- Suma[0]=0;
- for (i=1; i<=N; i++) {
- scanf("%ld",&Niz[i]);
- Suma[i]=Suma[i-1]+Niz[i];
- }
- printf("%ld",Opt(1,N));
- return 0;
- }
Add Comment
Please, Sign In to add comment