結果
| 問題 |
No.997 Jumping Kangaroo
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2020-02-23 01:36:27 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 2,247 bytes |
| コンパイル時間 | 1,149 ms |
| コンパイル使用メモリ | 99,000 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-10 01:18:10 |
| 合計ジャッジ時間 | 1,897 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
ソースコード
/* -*- coding: utf-8 -*-
*
* 997.cc: No.997 Jumping Kangaroo - yukicoder
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
/* constant */
const int MAX_W = 40;
const int MAX_W2 = MAX_W * 2;
const int MOD = 1000000007;
/* typedef */
typedef long long ll;
typedef int mat[2][2];
/* global variables */
int as[MAX_W2];
int dp[MAX_W2 + 1];
mat ma, mb;
/* subroutines */
inline void addmod(int &a, int b) { a = (a + b) % MOD; }
int do_dp(int n, int w) {
memset(dp, 0, sizeof(dp));
dp[0] = 1;
for (int i = 0; i < w; i++)
if (dp[i] > 0)
for (int j = 0; j < n && i + as[j] <= w; j++)
addmod(dp[i + as[j]], dp[i]);
return dp[w];
}
inline void initmat(mat a) { memset(a, 0, sizeof(mat)); }
inline void unitmat(mat a) { initmat(a); a[0][0] = a[1][1] = 1; }
inline void copymat(const mat a, mat b) { memcpy(b, a, sizeof(mat)); }
inline void mulmat(const mat a, const mat b, mat c) {
c[0][0] = ((ll)a[0][0] * b[0][0] % MOD + (ll)a[0][1] * b[1][0] % MOD) % MOD;
c[0][1] = ((ll)a[0][0] * b[0][1] % MOD + (ll)a[0][1] * b[1][1] % MOD) % MOD;
c[1][0] = ((ll)a[1][0] * b[0][0] % MOD + (ll)a[1][1] * b[1][0] % MOD) % MOD;
c[1][1] = ((ll)a[1][0] * b[0][1] % MOD + (ll)a[1][1] * b[1][1] % MOD) % MOD;
}
inline void powmat(const mat a, ll b, mat c) {
mat s, t;
copymat(a, s);
unitmat(c);
while (b > 0) {
if (b & 1) {
mulmat(c, s, t);
copymat(t, c);
}
mulmat(s, s, t);
copymat(t, s);
b >>= 1;
}
}
/* main */
int main() {
int n, w;
ll k;
scanf("%d%d%lld", &n, &w, &k);
int w2 = w * 2;
for (int i = 0; i < n; i++) scanf("%d", as + i);
sort(as, as + n);
int d1 = do_dp(n, w);
int d2 = (do_dp(n, w2) + (MOD - (ll)d1 * d1 % MOD)) % MOD;
//printf("%d %d\n", d1, d2);
// f_n = d1 * f_{n-1} + d2 * f_{n-2}
ma[0][0] = 0; ma[0][1] = 1;
ma[1][0] = d2; ma[1][1] = d1;
powmat(ma, k, mb);
int r = (mb[0][0] + (ll)mb[0][1] * d1 % MOD) % MOD;
printf("%d\n", r);
return 0;
}
tnakao0123