結果

問題 No.269 見栄っ張りの募金活動
ユーザー __t2kasa____t2kasa__
提出日時 2018-08-29 20:01:04
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 1,297 bytes
コンパイル時間 500 ms
コンパイル使用メモリ 64,772 KB
実行使用メモリ 11,432 KB
最終ジャッジ日時 2023-09-23 01:33:59
合計ジャッジ時間 1,508 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
11,280 KB
testcase_01 AC 5 ms
11,232 KB
testcase_02 AC 5 ms
11,248 KB
testcase_03 AC 6 ms
11,248 KB
testcase_04 AC 7 ms
11,240 KB
testcase_05 AC 5 ms
11,296 KB
testcase_06 AC 5 ms
11,232 KB
testcase_07 AC 9 ms
11,224 KB
testcase_08 AC 6 ms
11,224 KB
testcase_09 AC 5 ms
11,300 KB
testcase_10 AC 5 ms
11,232 KB
testcase_11 AC 6 ms
11,224 KB
testcase_12 AC 5 ms
11,284 KB
testcase_13 AC 6 ms
11,212 KB
testcase_14 AC 5 ms
11,228 KB
testcase_15 AC 6 ms
11,240 KB
testcase_16 AC 5 ms
11,312 KB
testcase_17 AC 5 ms
11,228 KB
testcase_18 AC 6 ms
11,236 KB
testcase_19 AC 5 ms
11,284 KB
testcase_20 AC 5 ms
11,280 KB
testcase_21 AC 5 ms
11,240 KB
testcase_22 AC 6 ms
11,280 KB
testcase_23 AC 5 ms
11,432 KB
testcase_24 AC 5 ms
11,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// https://yukicoder.me/problems/no/269
// status:
// tag: [分割数]
// ref: http://d.hatena.ne.jp/incognita/20110305/1299344781
// ref: http://drken1215.hatenablog.com/entry/2018/01/16/222843

#define SUBMIT
//#define DEBUG

#include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>

using namespace std;
using ui64 = unsigned long long;
using i64 = long long;

const int M = 1000000000 + 7;
const int MAX_S = 20000;
const int MAX_N = 100;

// dp[N][S] SのN分割の総数
// dp[n][s] = dp[n][s - n] + dp[n - 1][s]   (s >= n)
// dp[n][s] = dp[n][s - 1]                  (otherwise)
int dp[MAX_N + 1][MAX_S + 1];
int N, S, K;

// 分割数
// nのm分割を求める
int solve_partition(int m, int n) {
    // init
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;

    // partition
    for (int i = 1; i <= m; ++i) {
        for (int j = 0; j <= n; ++j) {
            if (j - i >= 0) dp[i][j] = (dp[i - 1][j] + dp[i][j - i]) % M;
            else dp[i][j] = dp[i - 1][j] % M;
        }
    }

    return dp[m][n];
}

int main() {
#ifdef SUBMIT
    auto& stream = cin;
#else
    stringstream stream(R"(55 2555 1
)");
#endif
    stream >> N >> S >> K;
    for (int i = 0; i < N; ++i) S -= i * K;

    auto ans = solve_partition(N, S);
    cout << ans << endl;
    return 0;
}
0