結果

問題 No.997 Jumping Kangaroo
ユーザー leaf_1415leaf_1415
提出日時 2020-02-21 22:22:43
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,909 bytes
コンパイル時間 632 ms
コンパイル使用メモリ 62,436 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-17 07:42:14
合計ジャッジ時間 1,387 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 1 ms
6,944 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 1 ms
6,944 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 1 ms
6,944 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 1 ms
6,940 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 1 ms
6,944 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 1 ms
6,944 KB
testcase_27 AC 1 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#define llint long long
#define mod 1000000007

using namespace std;

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

struct Matrix{
	int h, w;
	vector<llint> mat;
	Matrix(){
		h = w = 0;
	}
	Matrix(int h, int w){
		this->h = h, this->w = w;
		mat.resize(h*w);
	}
	llint& at(int i, int j){
		return mat[w*(i-1)+(j-1)];
	}
	static Matrix ident(int size){
		Matrix ret(size, size);
		for(int i = 1; i <= size; i++) ret.at(i, i) = 1;
		return ret;
	}
	Matrix operator*(Matrix& ope){
		Matrix ret(h, ope.w);
		for(int i = 1; i <= h; i++){
			for(int j = 1; j <= ope.w; j++){
				for(int k = 1; k <= w; k++){
					ret.at(i, j) += at(i, k) * ope.at(k, j) % mod;
					ret.at(i, j) %= mod;
				}
			}
		}
		return ret;
	}
	Matrix pow(llint n){
		if(n == 0) return ident(h);
		if(n % 2){
			return pow(n-1) * (*this);
		}
		else{
			Matrix tmp = pow(n/2);
			return tmp * tmp;
		}
	}
	void print(){
		for(int i = 1; i <= h; i++){
			for(int j = 1; j <= w; j++){
				cout << at(i, j) << " ";
			}
			cout << endl;
		}
	}
};

llint n, w, k;
llint a[105];
llint dp[105], dp2[105];
llint x1, x2;
Matrix mat;

int main(void)
{
  ios::sync_with_stdio(0);
  cin.tie(0);

  cin >> n >> w >> k;
	for(int i = 1; i <= n; i++) cin >> a[i];

	dp[0] = 1;
	for(int i = 0; i < w; i++){
		for(int j = 1; j <= n; j++){
			if(i+a[j] <= w) dp[i+a[j]] += dp[i], dp[i+a[j]] %= mod;
		}
	}
	x1 = dp[w];

	dp2[0] = 1;
	for(int i = 0; i < 2*w; i++){
		if(i == w) continue;
		for(int j = 1; j <= n; j++){
			if(i+a[j] <= 2*w) dp2[i+a[j]] += dp2[i], dp2[i+a[j]] %= mod;
		}
	}
	x2 = dp2[2*w];

	mat = Matrix(2, 2);
	mat.at(1, 1) = x1, mat.at(1, 2) = x2;
	mat.at(2, 1) = 1, mat.at(2, 2) = 0;

	Matrix pmat = mat.pow(k);
	cout << pmat.at(1, 1) << endl;

  return 0;
}
0