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 MAX_ECOLE=501,INFINI=1000*1000*1000+7;
int nbEcole;
map<long long,int> memo;
int mini[MAX_ECOLE],maxi[MAX_ECOLE];
int dyna(int idEcole,int maxMaint) {
if (idEcole==nbEcole+1) {
return 1;
}
if (maxMaint<mini[idEcole]) {
return memo[(long long)idEcole*(long long)INFINI+(long long)maxMaint]=(dyna(idEcole+1,maxMaint)+dyna(idEcole,mini[idEcole]))%INFINI;
}
int val=memo[(long long)idEcole*(long long)INFINI+(long long)maxMaint];
if (val!=0) {
return val;
}
val=dyna(idEcole+1,maxMaint);
if (maxMaint<maxi[idEcole]) {
val+=dyna(idEcole,maxMaint+1);
val%=INFINI;
}
memo[(long long)idEcole*(long long)INFINI+(long long)maxMaint]=val;
return val;
}
int main() {
ios_base::sync_with_stdio(false);
cin>>nbEcole;
for (int i=1;i<=nbEcole;i++) {
cin>>mini[i]>>maxi[i];
}
cout<<(dyna(1,-1)+INFINI-1)%INFINI<<endl;
}
# | 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... |