-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlec16_waystoN.cpp
57 lines (44 loc) Β· 1.03 KB
/
lec16_waystoN.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
https://www.geeksforgeeks.org/problems/ways-to-sum-to-n5759/1?utm_source=geeksforgeeks&utm_medium=article_practice_tab&utm_campaign=article_practice_tab
//{ Driver Code Starts
#include <bits/stdc++.h>
using namespace std;
// } Driver Code Ends
class Solution
{
public:
int way(int arr[] , int m , int sum)
{
if(sum == 0 ) return 1;
if(sum <0) return 0 ;
long long ans = 0;
for(int i = 0 ; i<m ; i++)
{
ans+= way(arr , m , sum - arr[i]);
}
return ans%1000000007;
}
// function to count the total
// number of ways to sum up to 'N'
int countWays(int arr[], int m, int N)
{
//code here.
return way(arr , m , N);
}
};
//{ Driver Code Starts.
int main()
{
int t;
cin>>t;
while(t--)
{
int m,n ;
cin>>m>>n;
int arr[m];
for(int i = 0;i<m;i++)
cin>>arr[i];
Solution ob;
cout<<ob.countWays(arr,m,n)<<endl;
}
}
// } Driver Code Ends