結果

問題 No.393 2本の竹
ユーザー femtofemto
提出日時 2016-07-12 01:40:12
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 539 ms / 1,000 ms
コード長 895 bytes
コンパイル時間 1,263 ms
コンパイル使用メモリ 70,824 KB
実行使用メモリ 241,856 KB
最終ジャッジ日時 2023-08-08 00:03:59
合計ジャッジ時間 15,721 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 479 ms
241,724 KB
testcase_01 AC 487 ms
241,728 KB
testcase_02 AC 488 ms
241,536 KB
testcase_03 AC 478 ms
241,672 KB
testcase_04 AC 476 ms
241,620 KB
testcase_05 AC 476 ms
241,528 KB
testcase_06 AC 478 ms
241,580 KB
testcase_07 AC 489 ms
241,788 KB
testcase_08 AC 489 ms
241,660 KB
testcase_09 AC 539 ms
241,656 KB
testcase_10 AC 497 ms
241,732 KB
testcase_11 AC 503 ms
241,664 KB
testcase_12 AC 508 ms
241,824 KB
testcase_13 AC 505 ms
241,528 KB
testcase_14 AC 493 ms
241,556 KB
testcase_15 AC 194 ms
241,564 KB
testcase_16 AC 378 ms
241,580 KB
testcase_17 AC 477 ms
241,732 KB
testcase_18 AC 479 ms
241,600 KB
testcase_19 AC 370 ms
241,664 KB
testcase_20 AC 481 ms
241,524 KB
testcase_21 AC 481 ms
241,856 KB
testcase_22 AC 504 ms
241,736 KB
testcase_23 AC 490 ms
241,672 KB
testcase_24 AC 480 ms
241,768 KB
testcase_25 AC 443 ms
241,852 KB
testcase_26 AC 402 ms
241,528 KB
testcase_27 AC 479 ms
241,568 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