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>
#define MAXN 2007
using namespace std;
const int mod=1e9+7;
int n,m,a,b,ans;
int dp[MAXN][30];
int maxs[MAXN][MAXN],maxs2[MAXN][MAXN],es[MAXN],es2[MAXN];
bool bad[MAXN],bad2[MAXN];
void calc_dp(){
for(int pos=n;pos>=1;pos--){
for(int f=pos+1;f<=es[pos];f++)bad[f]=true;
for(int f=pos+1;f<=es2[pos];f++)bad2[f]=true;
for(int letter=0;letter<26;letter++){
dp[pos][letter]=1;
for(int nxtletter=0;nxtletter<26;nxtletter++){
if(nxtletter==letter)continue;
for(int f=pos+1;f<=n;f++){
if(nxtletter<letter and !bad[f]){
dp[pos][letter]+=dp[f][nxtletter];
dp[pos][letter]%=mod;
}
if(nxtletter>letter and !bad2[f]){
dp[pos][letter]+=dp[f][nxtletter];
dp[pos][letter]%=mod;
}
}
}
}
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
for(int i=1;i<=m;i++){
cin>>a>>b;
if(a<b){
es[a]=max(es[a],b);
}else{
es2[b]=max(es2[b],a);
}
}
calc_dp();
for(int i=0;i<26;i++){
ans+=dp[1][i];
ans%=mod;
}
cout<<ans<<"\n";
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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |