Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Let f(i, j) be the number of ways of distributing j chocolates to the first i people.

Then we can give the j-th person - 0, 1, 2, ... , A[i] chocolates.
Then we can give the i-th person - 0, 1, 2, ... , A[i] chocolates.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The i-th person can get a[i] candies. not the j-th


So, f(i, j) = f(i - 1, j ) + f(i - 1, j - 1) + ... + f(i - 1, j - A[i] - 1)

If (j - A[i] - 1), then f(i, j) = f(i - 1, j) + ... + f(i - 1, 0).
If (j = A[i] - 1), then f(i, j) = f(i - 1, j) + ... + f(i - 1, 0).
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simply putting in the above formula


So the base case is that f(0, 0) = 1 and f(0, j) = 0 for all other j.

Expand Down Expand Up @@ -54,4 +54,4 @@ int main()

cout << no_of_ways[no_of_people][no_of_candies];
return 0;
}
}