From 5385703610733cfb5c1d477ef99950648b03617b Mon Sep 17 00:00:00 2001 From: oncsr Date: Sun, 28 Dec 2025 15:36:41 +0900 Subject: [PATCH] =?UTF-8?q?[20251228]=20BOJ=20/=20P5=20/=20=EC=9D=B8?= =?UTF-8?q?=EA=B2=BD=ED=98=B8=EC=9D=98=20=EB=82=98=EB=AC=B4=20/=20?= =?UTF-8?q?=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\354\235\230 \353\202\230\353\254\264.md" | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 "khj20006/202512/28 BOJ P5 \354\235\270\352\262\275\355\230\270\354\235\230 \353\202\230\353\254\264.md" diff --git "a/khj20006/202512/28 BOJ P5 \354\235\270\352\262\275\355\230\270\354\235\230 \353\202\230\353\254\264.md" "b/khj20006/202512/28 BOJ P5 \354\235\270\352\262\275\355\230\270\354\235\230 \353\202\230\353\254\264.md" new file mode 100644 index 00000000..08a19519 --- /dev/null +++ "b/khj20006/202512/28 BOJ P5 \354\235\270\352\262\275\355\230\270\354\235\230 \353\202\230\353\254\264.md" @@ -0,0 +1,47 @@ +```cpp +#include +using namespace std; +using ll = long long; + +const ll MOD = 1e9 + 7; + +int N, M; +int a[1001]{}, l[1001]{}, r[1001]{}; +ll c[2001][1001]{}; + +vector res; + +void inorder(int n) { + if(l[n] != -1) inorder(l[n]); + res.push_back(a[n]); + if(r[n] != -1) inorder(r[n]); +} + +int main() { + cin.tie(0)->sync_with_stdio(0); + + for(int k=1;k<=2000;k++) { + c[k][1] = k; + for(int i=2;i<=min(k,1000);i++) c[k][i] = (c[k-1][i-1] + c[k-1][i]) % MOD; + } + + cin>>N>>M; + for(int i=1;i<=N;i++) cin>>a[i]>>l[i]>>r[i]; + + inorder(1); + res.push_back(M+1); + ll ans = 1, prev = 0; + for(int i=0;i res[i] - prev - 1) return cout<<0,0; + ans = (ans * c[res[i]-prev-1][cnt]) % MOD; + } + prev = res[i]; + } + cout<