Patrickmeme

D - Money in Hand

Jun 14th, 2023
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <bitset>
  3. using namespace std;
  4.  
  5.  
  6. bitset <10001> dp[2];
  7. int v[2500];
  8. int main()
  9. {
  10.     int n,x,i,j,aux,a,b;
  11.     cin>>aux>>x;
  12.     for(i=0;i<aux;i++){
  13.         cin>>a>>b;
  14.         for(j=0;j<b;j++){
  15.             v[n]=a;
  16.             n++;
  17.         }
  18.     }
  19.     dp[0][0]=1;
  20.     for(i=0;i<n;i++){
  21.         for(j=0;j<=x;j++){
  22.             if(dp[0][j]==1){
  23.                 dp[1][j]=1;
  24.                 if(j+v[i]<=x)
  25.                     dp[1][j+v[i]]=1;
  26.             }
  27.         }
  28.         for(j=0;j<=x;j++){
  29.             dp[0][j]=dp[1][j];
  30.             dp[1][j]=0;
  31.         }
  32.     }
  33.     if(dp[0][x]==1)
  34.         cout<<"Yes";
  35.     else
  36.         cout<<"No";
  37.     return 0;
  38. }
Add Comment
Please, Sign In to add comment