Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp> // Common file
- #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
- using namespace std;
- using namespace __gnu_pbds;
- typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
- const int maxn = 50;
- int n, A;
- long long dp[maxn + 3][2500 + 3][maxn + 3];
- long long arr[maxn + 3];
- long long solve(long long index, long long sum, long long numberOfChosen)
- {
- if(index == n)
- {
- return (numberOfChosen != 0 && sum % A == 0 && numberOfChosen * A == sum);
- }
- if(dp[index][sum][numberOfChosen] != -1)
- return dp[index][sum][numberOfChosen];
- long long ans = 0;
- //try leaving the current card and do not take it with me
- ans += solve(index + 1, sum, numberOfChosen);
- //try takig the current card and incraese the sum with the curret card value, and numberOfChosen increases by 1.
- ans += solve(index + 1, sum + arr[index], numberOfChosen + 1);
- return dp[index][sum][numberOfChosen] = ans;
- }
- int main()
- {
- cin >> n >> A;
- for(int i = 0; i < n; i++)
- cin >> arr[i];
- memset(dp, -1, sizeof dp);
- cout << solve(0, 0, 0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement