matheus_monteiro

Troco - 100 pontos - DP

Aug 20th, 2021 (edited)
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int MAX = 500005;
  4.  
  5. int32_t main() {
  6.     ios_base::sync_with_stdio(false);
  7.     cin.tie(nullptr);
  8.    
  9.     int v, n;
  10.     cin >> v >> n;
  11.     vector<int> p(n);
  12.     for(int &w : p)
  13.         cin >> w;
  14.  
  15.     vector<int> dp(MAX);
  16.  
  17.     dp[0] = 1;
  18.     for(int &w : p)
  19.         for(int j = v; j >= w; j--)
  20.             if(dp[j - w])
  21.                 dp[j] = 1;
  22.  
  23.     cout << (dp[v] ? 'S' : 'N') << endl;
  24.  
  25.     return 0;
  26. }
  27.  
Add Comment
Please, Sign In to add comment