fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. vector<vector<int>> dp;
  5. int possible(int sum, int n, int arr[])
  6. {
  7. for(int i=1;i<sum;i++){
  8. dp[i][0] = 0;
  9. }
  10. for(int i=0;i<n;i++){
  11. dp[0][i] = 1;
  12. }
  13. for(int i=1;i<sum;i++){
  14. for(int j=1;j<n;j++){
  15. dp[i][j] = dp[i][j-1];
  16. if(arr[j-1] <= i){
  17. dp[i][j] += dp[i-arr[j-1]][j];
  18. }
  19. }
  20. }
  21.  
  22. return dp[sum][n];
  23.  
  24. }
  25.  
  26.  
  27.  
  28.  
  29. int main() {
  30. // your code goes here
  31. return 0;
  32. int n;
  33. cin >> n;
  34. int arr[n], sum;
  35. cin >> sum;
  36. for(int i: arr){
  37. cin >> arr[i];
  38. }
  39.  
  40. int res = possible(sum, n, arr);
  41. cout << res;
  42. }
Success #stdin #stdout 0s 5428KB
stdin
5
3
1 2 3 5 6
stdout
Standard output is empty