fork download
  1. /*
  2.   shool : Cu Chi High School
  3.   participant : Ngo Quoc Binh
  4. */
  5. #include <bits/stdc++.h>
  6. using namespace std;
  7.  
  8. #define debug(x) cerr << #x << " = " << x << "\n";
  9. #define vdebug(a) cerr << #a << " = "; for(auto x : a) cout << x << " "; cout << "\n";
  10. #define TIME cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s\n";
  11. #define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  12. #define hashmap unordered_map
  13. #define hashset unordered_set
  14. #define all(x) (x).begin(),(x).end()
  15. #define rall(x) (x).rbegin(),(x).rend()
  16. #define rev(x) reverse(all(x))
  17. #define sz(x) ((int)((x).size()))
  18. #define max_arr(x) *max_element(all(x))
  19. #define min_arr(x) *min_element(all(x))
  20.  
  21. #define pb push_back
  22. #define pf push_front
  23. #define PB pop_back
  24. #define PF pop_front
  25. #define en '\n'
  26. #define ff first
  27. #define ss second
  28. #define task "wtf"
  29.  
  30. using ll = long long;
  31. using ull = unsigned long long;
  32. using ld = long double;
  33.  
  34. mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
  35.  
  36. void solve()
  37. {
  38. int x,n;
  39. cin >> x >> n;
  40. vector<ull> c(n);
  41. for(int i = 0 ; i < n ; i++) cin >> c[i];
  42.  
  43. sort(all(c));
  44. c.erase(unique(all(c)),c.end());
  45.  
  46. vector<ull> dp(x + 1,0);
  47. dp[0] = 1;
  48.  
  49. for(ull d : c)
  50. {
  51. for(int res = d ; res <= x ; res++)
  52. {
  53. dp[res] += dp[res - d];
  54. }
  55. }
  56.  
  57. cout << dp[x];
  58. }
  59.  
  60. int main()
  61. {
  62. fastIO
  63.  
  64. solve();
  65.  
  66. return 0;
  67. }
Success #stdin #stdout 0s 5308KB
stdin
6
3
2 7 3
stdout
2