Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<algorithm>
- #include<time.h>
- using namespace std;
- void rec(int x, int y, int z, int w, int& count, int sum=0,int chet=0) {
- if (sum == w) {
- count ++;
- return;
- }
- if (sum > w) {
- return;
- }
- if (sum + x <= w and chet <=1) {
- rec(x, y, z, w, count, sum + x,1);
- }
- if (sum + y <= w and chet <=2) {
- rec(x, y, z,w, count, sum + y,2);
- }
- if (sum + z) {
- rec(x, y, z, w, count, sum + z,3);
- }
- }
- int main()
- {
- int x, y, z, w, count = 0;
- cin >> x >> y >> z >> w;
- rec(x, y, z, w, count);
- cout << count;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement