結果

問題 No.5 数字のブロック
ユーザー haruteruharuteru
提出日時 2018-02-01 11:47:33
言語 C++11
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 470 bytes
コンパイル時間 743 ms
コンパイル使用メモリ 59,420 KB
実行使用メモリ 13,640 KB
最終ジャッジ日時 2024-12-31 00:15:32
合計ジャッジ時間 128,098 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 13 TLE * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <iostream>
#include <vector>
using namespace std;

int L;
int N;
vector<int> W;

int solve(int i, int l, int cnt)
{
    if (l > L) return cnt - 1;
    if (i >= N || l == L) return cnt;
    int a1 = solve(i+1, l, cnt);
    int a2 = solve(i+1, l+W[i], cnt+1);
    return max(a1, a2);
}

int main()
{
    cin >> L;
    cin >> N;
    W.resize(N);
    for (int n = 0; n < N; n++) {
        cin >> W[n];
    }
    printf("%d\n", solve(0, 0, 0));
}
0