結果

問題 No.269 見栄っ張りの募金活動
ユーザー 🍡yurahuna🍡yurahuna
提出日時 2016-02-27 15:59:27
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 26 ms / 5,000 ms
コード長 1,376 bytes
コンパイル時間 583 ms
コンパイル使用メモリ 74,296 KB
実行使用メモリ 19,028 KB
最終ジャッジ日時 2023-09-23 01:16:16
合計ジャッジ時間 1,833 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 3 ms
4,648 KB
testcase_04 AC 11 ms
9,460 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 26 ms
19,028 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 13 ms
10,576 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 4 ms
4,960 KB
testcase_12 AC 10 ms
9,072 KB
testcase_13 AC 5 ms
5,400 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 5 ms
5,176 KB
testcase_16 AC 9 ms
8,492 KB
testcase_17 AC 3 ms
4,520 KB
testcase_18 AC 17 ms
13,384 KB
testcase_19 AC 5 ms
5,916 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 3 ms
4,504 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <complex>
#include <queue>
#include <map>
#include <string>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

#define PI 3.1415926535

typedef long long ll;
typedef pair<int, int> P;
//typedef complex<double> C;

const int MAX_N = 100;
const int MAX_S = 20000;

const ll mod = 1000000007;

int N, S, K;

// dp[i][j] = i番目まで人の和がj円となるような場合の数
ll dp[MAX_N][MAX_S + 1];

void input() {
	cin >> N >> S >> K;
}

void solve() {
	// 最初の人はN円の重みをもったナップザック
	// 個数はいくつでも入れられる
	int j = 0;
	while (N * j <= S) {
		dp[0][N * j] = 1;
		j++;
	}
	FOR(i, 1, N) {
		REP(j, S + 1) {
			// i番目の人は N-i円の重みをもったナップザック
			int w = N - i;
			if (j >= w) {
				// 既に前の人よりK円多く払っているがさらに1円増やす
				dp[i][j] += dp[i][j - w];
			}
			if (j >= K * w) {
				// 前の人よりK円増やす(全体ではK*w円)
				dp[i][j] += dp[i - 1][j - K * w];
			}
			dp[i][j] %= mod;
		}
	}
	cout << dp[N - 1][S] << endl;
}

int main() {
	input();
	solve();
}
0