結果

問題 No.393 2本の竹
ユーザー femtofemto
提出日時 2016-07-12 01:40:12
言語 C++11
(gcc 8.5.0)
結果
AC  
実行時間 521 ms / 1,000 ms
コード長 895 bytes
コンパイル時間 480 ms
使用メモリ 241,836 KB
最終ジャッジ日時 2022-12-14 14:17:06
合計ジャッジ時間 15,186 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 473 ms
241,780 KB
testcase_01 AC 471 ms
241,776 KB
testcase_02 AC 475 ms
241,780 KB
testcase_03 AC 470 ms
241,740 KB
testcase_04 AC 472 ms
241,824 KB
testcase_05 AC 471 ms
241,756 KB
testcase_06 AC 471 ms
241,676 KB
testcase_07 AC 473 ms
241,776 KB
testcase_08 AC 474 ms
241,676 KB
testcase_09 AC 521 ms
241,680 KB
testcase_10 AC 481 ms
241,680 KB
testcase_11 AC 494 ms
241,772 KB
testcase_12 AC 498 ms
241,740 KB
testcase_13 AC 485 ms
241,772 KB
testcase_14 AC 472 ms
241,740 KB
testcase_15 AC 188 ms
241,836 KB
testcase_16 AC 369 ms
241,728 KB
testcase_17 AC 472 ms
241,680 KB
testcase_18 AC 470 ms
241,676 KB
testcase_19 AC 365 ms
241,724 KB
testcase_20 AC 472 ms
241,772 KB
testcase_21 AC 475 ms
241,744 KB
testcase_22 AC 496 ms
241,736 KB
testcase_23 AC 481 ms
241,800 KB
testcase_24 AC 474 ms
241,744 KB
testcase_25 AC 436 ms
241,680 KB
testcase_26 AC 398 ms
241,824 KB
testcase_27 AC 472 ms
241,776 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][1000000];

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