This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const int MX = 505;
const int Mod = 1e9 + 7;
int a[MX], b[MX];
map<tuple<int,int,int>,int>dp;
int n;
int solve(int i, int prev, int more) {
if(i>n) return (prev!=0);
if(dp.count(make_tuple(i, prev, more))) return dp[make_tuple(i, prev, more)];
int ret = 0;
ret = solve(i+1, prev, more);
for(int cur=max(a[i], a[prev]+more+1); cur<=b[i]; ++cur) {
ret += solve(i+1, i, cur-a[i]);
if(ret>=Mod) ret -= Mod;
}
return dp[make_tuple(i, prev, more)] = ret;
}
void PlayGround() {
cin >> n;
for(int i=1; i<=n; ++i) {
cin >> a[i] >> b[i];
}
cout << solve(1, 0, 0) << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
PlayGround();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |