Official
D - お弁当の選択 / Choosing a Lunch Box Editorial
by
D - お弁当の選択 / Choosing a Lunch Box Editorial
by
physics0523
弁当の総数 \(S=A \times B \times C\) としたとき、答えは \(S \times (S-1) \times \dots \times (S-N+1)\) です。
これは、 \(S\) 種の弁当から \(N\) 個を重複なく選んで並べる方法の数と同じです。
計算途中のオーバーフローに注意してください。
実装例 (C++):
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mod=1000000007;
int main(){
ll N,A,B,C;
cin >> N >> A >> B >> C;
ll res=1,mul=(A*B*C)%mod;
while(N--){
res*=mul; res%=mod;
mul+=(mod-1); mul%=mod;
}
cout << res << "\n";
return 0;
}
posted:
last update:
