結果

問題 No.115 遠足のおやつ
コンテスト
ユーザー くれちー
提出日時 2017-02-22 17:32:36
言語 C90(gcc15)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=c90 -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
RE  
実行時間 -
コード長 1,124 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 281 ms
コンパイル使用メモリ 38,608 KB
最終ジャッジ日時 2026-02-24 00:23:33
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36 RE * 4
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#define rep(i, n) for (i = 0; i < n; i++)
#define rrep(i, n) for (i = n; i >= 0; i--)
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
typedef long long ll;

int n, d, k, dp[100][5050][100];
bool buy[101];

bool dfs(int idx, int sum, int cnt) {
    if (dp[idx][sum][cnt] != -1) return dp[idx][sum][cnt];

    if (sum == d && cnt == k) return dp[idx][sum][cnt] = true;
    if (sum > d) return dp[idx][sum][cnt] = false;
    if (cnt > k) return dp[idx][sum][cnt] = false;
    if (idx > n) return dp[idx][sum][cnt] = false;

    if (dfs(idx + 1, sum + idx, cnt + 1)) {
        buy[idx] = true;
        return dp[idx][sum][cnt] = true;
    }
    if (dfs(idx + 1, sum, cnt)) {
        buy[idx] = false;
        return dp[idx][sum][cnt] = true;
    }
    return dp[idx][sum][cnt] = false;
}

int main() {
    scanf("%d %d %d", &n, &d, &k);
    memset(dp, -1, sizeof(dp));
    int i;
    if (dfs(1, 0, 0)) {
        rep(i, n + 1) { if (buy[i + 1]) printf("%d ", i + 1); }
    }
    else puts("-1");
    return 0;
}
0