結果

問題 No.393 2本の竹
ユーザー femtofemto
提出日時 2016-07-12 01:41:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 74 ms / 1,000 ms
コード長 894 bytes
コンパイル時間 519 ms
コンパイル使用メモリ 69,976 KB
実行使用メモリ 27,352 KB
最終ジャッジ日時 2024-04-25 18:11:42
合計ジャッジ時間 2,070 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
27,288 KB
testcase_01 AC 20 ms
27,224 KB
testcase_02 AC 20 ms
27,144 KB
testcase_03 AC 18 ms
27,136 KB
testcase_04 AC 20 ms
27,144 KB
testcase_05 AC 20 ms
27,212 KB
testcase_06 AC 22 ms
27,260 KB
testcase_07 AC 24 ms
27,156 KB
testcase_08 AC 21 ms
27,132 KB
testcase_09 AC 74 ms
27,228 KB
testcase_10 AC 30 ms
27,204 KB
testcase_11 AC 37 ms
27,172 KB
testcase_12 AC 34 ms
27,068 KB
testcase_13 AC 34 ms
27,140 KB
testcase_14 AC 25 ms
27,200 KB
testcase_15 AC 12 ms
27,036 KB
testcase_16 AC 22 ms
27,160 KB
testcase_17 AC 23 ms
27,168 KB
testcase_18 AC 19 ms
27,188 KB
testcase_19 AC 17 ms
27,296 KB
testcase_20 AC 19 ms
27,152 KB
testcase_21 AC 21 ms
27,180 KB
testcase_22 AC 46 ms
27,284 KB
testcase_23 AC 28 ms
27,352 KB
testcase_24 AC 20 ms
27,180 KB
testcase_25 AC 21 ms
27,260 KB
testcase_26 AC 20 ms
27,164 KB
testcase_27 AC 54 ms
27,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;

int a[60];
int s[60];
int dp[61][100010];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int d;
	cin >> d;
	while(d--) {
		int n1, n2, m;
		cin >> n1 >> n2 >> m;
		if(n1 > n2) swap(n1, n2);

		for(int i = 0; i < m; i++) {
			cin >> a[i];
		}
		sort(a, a + m);
		for(int i = 1; i < m; i++) {
			s[i] = s[i - 1] + a[i - 1];
		}

		memset(dp, -1, sizeof dp);
		dp[0][0] = 0;
		for(int i = 0; i < m; i++) {
			for(int j = 0; j <= n1; j++) if(dp[i][j] != -1) {
				dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
				if(j + a[i] <= n1)
					dp[i + 1][j + a[i]] = max(dp[i + 1][j + a[i]], dp[i][j] + 1);
				if(s[i] - j + a[i] <= n2)
					dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + 1);
			}
		}
		cout << *max_element(dp[m], dp[m] + n1 + 1) << endl;
	}
}
0