keymasterviriya1150

Untitled

Oct 17th, 2016
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.85 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<map>
  4. using namespace std;
  5. int knapSack(int W, int wt[], int val[], int n)
  6. {
  7.     int i, w;
  8.     int K[n + 1][W + 1];
  9.     for (i = 0; i <= n; i++)
  10.     {
  11.         for (w = 0; w <= W; w++)
  12.         {
  13.             if (i == 0 || w == 0)
  14.                 K[i][w] = 0;
  15.             else if (wt[i - 1] <= w)
  16.                 K[i][w]
  17.                     = max(val[i - 1] + K[i - 1][w - wt[i - 1]], K[i - 1][w]);
  18.             else
  19.                 K[i][w] = K[i - 1][w];
  20.         }
  21.     }
  22.  
  23.     return K[n][W];
  24. }
  25. int main()
  26. {
  27.  
  28.  
  29.     map<string,int > mp;
  30.     mp["HANDGUN"]=2;
  31.     mp["RED9"]=3.5;
  32.     mp["BLAKTAIL"]=3.5;
  33.     mp["MATILDA"]=2;
  34.     mp["HANDCANNON"]=60;
  35.     mp["STRIKER"]=12;
  36.     mp["TMP"]=1.2;
  37.     mp["RIFLE"]=1.2;
  38.     map<string,int > mp_2;
  39.     mp_2["GANADOS"]=50;
  40.     mp_2["COBRAS"]=40;
  41.     mp_2["ZEALOT"]=75;
  42.     mp_2["COLMILLOS"]=60;
  43.     mp_2["GARRADOR"]=125;
  44.     mp_2["LASPLAGAS"]=100;
  45.     mp_2["GATLINGMAN"]=150;
  46.     mp_2["REGENERATOR"]=250;
  47.     mp_2["ELGIGANTE"]=500;
  48.     mp_2["DR.SALVADOR"]=350;
  49.     int  N;
  50.     while(cin>>N)
  51.     {
  52.         int val[500],wt[500],bullet,c=0;
  53.         string gun;
  54.         for(int i=0; i<N; i++)
  55.         {
  56.             cin>> gun>> bullet;
  57.             while(bullet--)
  58.             {
  59.                 val[c]=mp[gun];
  60.                 wt[c]=1;
  61.                 c++;
  62.             }
  63.         }
  64.         int M;
  65.         cin>>M;
  66.         string moster;
  67.         int val_monster,result_monster=0;
  68.         for(int i=0; i<M; i++)
  69.         {
  70.             cin>> moster>> val_monster;
  71.             result_monster+=mp_2[moster]*val_monster;
  72.         }
  73.  
  74.         int W;
  75.         cin>>W;
  76.  
  77.         if(knapSack(W,wt,val,c)> result_monster)
  78.             cout <<"Missao completada com sucesso"<<endl <<endl ;
  79.         else  cout <<"You Are Dead"<<endl<<endl;
  80.     }
  81.     return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment