# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
758708 | Trisanu_Das | Boat (APIO16_boat) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1e9+7;
int dp[1005][505], inv[505], a[505], b[505], c[1005];
set<int> s;
int f(int x, int y) {
if (!y) return 1;
int res=f(x, y/2);
if (y&1) return res*res%mod*x%mod;
else return res*res%mod;
}
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
int n, m=0;
cin >> n;
for (int i=1; i<=n; i++) inv[i]=f(i, mod-2);
for (int i=1; i<=n; i++) {
cin >> a[i] >> b[i];
s.insert(a[i]);
s.insert(b[i]+1);
}
for (auto itr=s.begin(); itr!=s.end(); itr++) [++m]=(*itr);
for (int i=0; i<=n; i++) dp[0][i]=1;
for (int i=1; i<m; i++) {
for (int j=0; j<=n; j++) {
dp[i][j]=dp[i-1][j];
int num=1, cnt=0;
for (int k=1; k<=j; k++) {
if (a[j-k+1]<=c[i] && c[i+1]-1<=b[j-k+1]) {
cnt++;
num=num*(c[i+1]-c[i]+cnt-1)%mod*inv[cnt]%mod;
dp[i][j]=(dp[i][j]+dp[i-1][j-k]*num)%mod;
}
}
}
}
cout << dp[m-1][n]-1;
return 0;
}