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;
long long n , m , in [202] , de [202] , inmx [202] , demx [202] , mod = 1e9 + 7;
long long dp [202][202][31];
long long f ( int x , int y , int last )
{
if ( x == n + 1 ) return 1;
if ( dp [x][y][last] != -1 ) return dp [x][y][last];
long long ans = 0;
ans = ( ans = f ( x + 1 , y , last ) ) % mod;
int aa = 1 , bb = 1;
for ( int j = y ; j < x ; j ++ )
{
if ( demx [j] >= x ) aa = 0;
if ( inmx [j] >= x ) bb = 0;
}
if ( aa )
{
for ( int i = last + 1 ; i < 26 ; i ++ ) ans = ( ans + f ( x + 1 , x , i ) ) % mod;
}
if ( bb )
{
for ( int i = 0 ; i < last ; i ++ ) ans = ( ans + f ( x + 1 , x , i ) ) % mod;
}
return dp [x][y][last] = ans;
}
int main()
{
memset ( dp , -1 , sizeof dp );
cin >> n >> m;
for ( int i = 1 ; i <= n ; i ++ )
{
in [i] = 1e9;
de [i] = 1e9;
}
for ( int i = 0 ; i < m ; i ++ )
{
long long x , y;
cin >> x >> y;
if ( x < y )
{
de [x] = min ( de [x] , y );
demx [x] = max ( demx [x] , y );
}
if ( x > y )
{
in [y] = min ( in [y] , x );
inmx [y] = max ( inmx [y] , x );
}
}
cout << f ( 1 , 0 , 0 );
}
Compilation message (stderr)
misspelling.cpp: In function 'long long int f(int, int, int)':
misspelling.cpp:10:9: warning: operation on 'ans' may be undefined [-Wsequence-point]
10 | ans = ( ans = f ( x + 1 , y , last ) ) % mod;
| ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |