結果
問題 | No.498 ワープクリスタル (給料日編) |
ユーザー |
|
提出日時 | 2017-03-24 23:37:09 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 37 ms / 2,000 ms |
コード長 | 1,343 bytes |
コンパイル時間 | 1,559 ms |
コンパイル使用メモリ | 171,776 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-06 00:51:45 |
合計ジャッジ時間 | 2,577 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 1e9 + 7; ll f[80], fi[80]; int gx, gy, K; vector<int> x, y, n; ll modpow(ll x, ll n) { ll res = 1; while (n > 0) { if (n & 1) res = res * x % MOD; x = x * x % MOD; n >>= 1; } return res; } void init(int lim) { f[0] = 1; for (int i = 1; i <= lim; i++) f[i] = f[i - 1] * i % MOD; fi[lim] = modpow(f[lim], MOD - 2); for (int i = lim; i > 0; i--) fi[i - 1] = fi[i] * i % MOD; } bool judge(vector<int>& used) { int sx = 0, sy = 0; for (int i = 0; i < K; i++) { sx += x[i] * used[i]; sy += y[i] * used[i]; } return (sx == gx && sy == gy); } ll solve(vector<int>& used) { ll res = f[accumulate(used.begin(), used.end(), 0)]; for (int x : used) { (res *= fi[x]) %= MOD; } return res; } ll dfs(int cnt, vector<int> used) { if (cnt == K) { if (!judge(used)) return 0; else return solve(used); } ll res = 0; for (int i = 0; i <= n[cnt]; i++) { used[cnt] = i; (res += dfs(cnt + 1, used)) %= MOD; used[cnt] = 0; } return res; } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> gx >> gy >> K; x.resize(K); y.resize(K); n.resize(K); for (int i = 0; i < K; i++) cin >> x[i] >> y[i] >> n[i]; init(accumulate(n.begin(), n.end(), 0)); vector<int> used(K, 0); cout << dfs(0, used) << endl; return 0; }