結果
| 問題 | No.617 Nafmo、買い出しに行く | 
| コンテスト | |
| ユーザー |  pin | 
| 提出日時 | 2017-12-21 00:32:16 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 6 ms / 2,000 ms | 
| コード長 | 579 bytes | 
| コンパイル時間 | 754 ms | 
| コンパイル使用メモリ | 81,356 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-12-16 07:27:19 | 
| 合計ジャッジ時間 | 1,586 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 20 | 
ソースコード
#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm> 
#include <math.h>
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
int n, k;
int a[25];
int dfs(int i, int j){
    if (i == n) return 0;
    int ret;
    ret = dfs(i + 1, j);
    if (j + a[i] <= k){
        ret = max(ret, a[i] + dfs(i + 1, j + a[i]));
    }
    return ret;
}
int main(void){
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> a[i];
    cout << dfs(0, 0) << endl;
}
            
            
            
        