#include <bits/stdc++.h>
using namespace std;
#define fori(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define mod 1e9 + 7
ll int count(int s[], int m, int n)
{
ll int t[m + 1][n + 1];
for (int i = 0; i < m + 1; i++)
{
for (int j = 0; j < n + 1; j++)
{
if (i == 0)
t[i][j] = 0;
if (j == 0)
t[i][j] = 1;
}
}
for (int i = 1; i < m + 1; i++)
{
for (int j = 1; j < n + 1; j++)
{
if (s[i - 1] > j)
t[i][j] = t[i - 1][j];
else if (s[i - 1] <= j)
{
t[i][j] = t[i - 1][j] + t[i][j - s[i - 1]];
}
}
}
return t[m][n];
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif //
int arr[] = {1, 2, 3};
int m = 3, n = 4;
std::cout << count(arr, m, n) << std::endl;
return 0;
}
i need to print all the combination possible in the coin change problem using the above code. like if we have an array {1,2,3} and we need to total of 4 using the array then we have Four Possible ways are:
{1,1,1,1},{1,1,2},{2,2},{1,3}
is there a way to print all ways using the above code? Thanks