Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp> // Common file
  3. #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
  4. using namespace std;
  5. using namespace __gnu_pbds;
  6. typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
  7.  
  8. const int maxn = 50;
  9. int n, A;
  10. long long dp[maxn + 3][2500 + 3][maxn + 3];
  11. long long arr[maxn + 3];
  12.  
  13. long long solve(long long index, long long sum, long long numberOfChosen)
  14. {
  15. if(index == n)
  16. {
  17. return (numberOfChosen != 0 && sum % A == 0 && numberOfChosen * A == sum);
  18. }
  19. if(dp[index][sum][numberOfChosen] != -1)
  20. return dp[index][sum][numberOfChosen];
  21. long long ans = 0;
  22. //try leaving the current card and do not take it with me
  23. ans += solve(index + 1, sum, numberOfChosen);
  24. //try takig the current card and incraese the sum with the curret card value, and numberOfChosen increases by 1.
  25. ans += solve(index + 1, sum + arr[index], numberOfChosen + 1);
  26. return dp[index][sum][numberOfChosen] = ans;
  27. }
  28.  
  29. int main()
  30. {
  31. cin >> n >> A;
  32. for(int i = 0; i < n; i++)
  33. cin >> arr[i];
  34. memset(dp, -1, sizeof dp);
  35. cout << solve(0, 0, 0);
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement