-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathBEHAPPY.cpp
More file actions
39 lines (34 loc) · 745 Bytes
/
BEHAPPY.cpp
File metadata and controls
39 lines (34 loc) · 745 Bytes
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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007LL
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);
const int MAXN = 1e2+5;
int gf, gifts;
int A[MAXN], B[MAXN];
int solve(int idx, int left){
if(idx < 0) return 1;
if(left < 0) return 0;
if(idx == 0){
if(left >= A[0] && left <= B[0]) return 1;
else return 0;
}
int res = 0;
for(int i = A[idx]; i <= B[idx]; i++){
res += solve(idx - 1, left - i);
}
return res;
}
int main(){
io;
while(1){
cin >> gf >> gifts;
if(gf == 0 && gifts == 0)
break;
for(int i = 0;i < gf; i++)
cin >> A[i] >> B[i];
cout << solve(gf - 1, gifts) << endl;
}
return 0;
}