結果

問題 No.393 2本の竹
ユーザー tnakao0123tnakao0123
提出日時 2016-07-17 17:41:56
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 38 ms / 1,000 ms
コード長 1,453 bytes
コンパイル時間 748 ms
コンパイル使用メモリ 86,232 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-08 09:26:55
合計ジャッジ時間 1,890 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

/* -*- coding: utf-8 -*-
*
* 393.cc: No.393 2 - yukicoder
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
/* constant */
const int MAX_N = 100000;
const int MAX_M = 60;
/* typedef */
/* global variables */
int as[MAX_M], dp[2][MAX_N + 1];
/* subroutines */
/* main */
int main() {
int tn;
cin >> tn;
while (tn--) {
int n0, n1, m;
cin >> n0 >> n1 >> m;
for (int i = 0; i < m; i++) cin >> as[i];
sort(as, as + m);
memset(dp, -1, sizeof(dp));
dp[0][0] = 0;
int cur = 0, nxt = 1, asum = 0;
for (int i = 0; i < m; i++) {
bool cont = false;
memset(dp[nxt], -1, sizeof(dp[nxt]));
for (int j = 0; j <= n0; j++)
if (dp[cur][j] >= 0) {
int d = dp[cur][j] + 1;
int j0 = j + as[i];
if (j0 <= n0 && dp[nxt][j0] < d)
dp[nxt][j0] = d, cont = true;
int j1 = asum - j + as[i];
if (j1 <= n1 && dp[nxt][j] < d)
dp[nxt][j] = d, cont = true;
}
if (! cont) break;
asum += as[i];
cur ^= 1, nxt ^= 1;
}
int maxdp = 0;
for (int i = 0; i <= n0; i++)
if (maxdp < dp[cur][i]) maxdp = dp[cur][i];
printf("%d\n", maxdp);
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0