#include "bits/stdc++.h"
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
typedef long long ll;
typedef string str;
typedef double db;
typedef long double ld;
typedef pair<int, int> pi;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
const ll MOD = 1e9 + 7; //998244353
const ll INF = 1e18;
const ll MX = 1e9 + 10;
const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0}; //right left down up
#ifndef LOCAL
#define cerr if(false) cerr
#endif
#define debug(x) cerr << #x << " : " << x << endl;
#define debugs(x,y) cerr << #x << " : " << x << " / " << #y << " : " << y << endl;
#define debugv(v) cerr << #v << " : " << "[ "; for(auto it : v) cerr << it << ' '; cerr << ']' << endl;
#define here() cerr << "here" << endl;
void IO() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
vector<pair<int, int>> v;
ll solve(vector<vector<ll>> &dp, ll n, ll m)
{
if(dp[n][m]!=-1)
return dp[n][m];
if(n==0)
{
return dp[n][m] = 1%MOD;
}
if(m==0)
return dp[n][m] = 1%MOD;
ll res = 0;
FOR(i, v[n-1].fi, v[n-1].se+1)
{
if(i<m&&m>=1)
res += (solve(dp, n-1, m-1)%MOD);
res+= (solve(dp, n-1, m)%MOD);
}
return dp[n][m] = res%MOD;
}
int main()
{
boost;
IO();
ll n;
cin >> n;
ll a, b;
FOR(i, 0, n)
{
cin >> a >> b;
v.pb(mp(a, b));
}
ll res = 0;
FOR(j, v[n-1].fi, v[n-1].se+1)
{
vector<vector<ll>> dp(n, vector<ll>(j+1, -1));
dp[0][j] = 1;
solve(dp, n-1, j);
res = (res + dp[n-1][j])%MOD;
}
cout << res%MOD << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
244 ms |
524292 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
244 ms |
524292 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
251 ms |
524292 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
244 ms |
524292 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |