Latest

6/recent/ticker-posts

GAME: Choice of area

 Consider a game where we are given two types of power A and B and three types of area X,Y,Z. Every second you have to switch between these areas, each area has specific properties by which your power A and power B increase or decrease. We need to keep choosing areas in such a way that our survival time is maximized. Survival time ends when any of the powers, A or B reaches less than 0.


#include < bits/stdc++.h >
using namespace std;

int Survival(int A,int B, int x1,int x2,int y1,int y2,int z1,int z2,int last,map < pair < int,int > ,int > mp)
{
          if(A <=0 || B <=0)
                    return 0;
          pair < int,int > current=make_pair(A,B);
          if(mp.find(current)!=mp.end())
                    return mp[current];

          int temp;
          if(last==1)
                    temp=1+max(Survival(A+y1,B+y2,x1,x2,y1,y2,z1,z2,2,mp),Survival(A+z1,B+z2,x1,x2,y1,y2,z1,z2,3,mp));
          else if(last==2)
                    temp=1+max(Survival(A+x1,B+x2,x1,x2,y1,y2,z1,z2,1,mp),Survival(A+z1,B+z2,x1,x2,y1,y2,z1,z2,3,mp));
          else
                    temp=1+max(Survival(A+y1,B+y2,x1,x2,y1,y2,z1,z2,2,mp),Survival(A+x1,B+x2,x1,x2,y1,y2,z1,z2,1,mp));
          mp[current]=temp;
          return temp;
}

int main()

{
       int A,B,x1,x2,y1,y2,z1,z2;
       cin >> A >> B;
       cin >> x1 >> x2;
       cin >> y1 >> y2;
       cin >> z1 >> z2;
       map < pair < int,int > ,int > mp;
       int ans=0;
       if(A <=0 || B <=0)
          ans=0;
       else
       {
                  ans=max(Survival(A+x1,B+x2,x1,x2,y1,y2,z1,z2,1,mp),max(Survival(A+y1,B+y2,x1,x2,y1,y2,z1,z2,2,mp),Survival(A+z1,B+z2,x1,x2,y1,y2,z1,z2,3,mp)));
       }
        cout << ans;
        return 0;
}


20    8

3    2

-5    -10

-20    5




Post a Comment

0 Comments