結果

問題 No.393 2本の竹
ユーザー どららどらら
提出日時 2016-07-14 21:45:56
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,403 bytes
コンパイル時間 857 ms
コンパイル使用メモリ 94,588 KB
実行使用メモリ 126,784 KB
最終ジャッジ日時 2024-04-23 01:54:15
合計ジャッジ時間 5,297 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <stack>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;

int solve(int n1, int n2, const vector<int>& v){
  map< pair<int,int>, int> dp[65];

  dp[0][make_pair(0,0)] = 0;
  rep(i,v.size()){
    FOR(it,dp[i]){
      pair<int,int> p = it->first;
      int x = it->second;

      dp[i+1][p] = max(dp[i+1][p], x);
      if(p.first+v[i]<=n1) dp[i+1][make_pair(p.first+v[i],p.second)] = max(dp[i+1][make_pair(p.first+v[i],p.second)], x + 1);
      if(p.second+v[i]<=n2) dp[i+1][make_pair(p.first,p.second+v[i])] = max(dp[i+1][make_pair(p.first,p.second+v[i])], x + 1);
    }
  }

  int ret = 0;
  FOR(it,dp[v.size()]){
    ret = max(ret, it->second);
  }
  return ret;
}

int main(){
  ios::sync_with_stdio(false);
  int d;
  cin >> d;
  rep(i,d){
    int n1, n2;
    int m;
    cin >> n1 >> n2;
    cin >> m;
    vector<int> A;
    rep(j,m){
      int a;
      cin >> a;
      A.push_back(a);
    }
    cout << solve(n1, n2, A) << endl;
  }
  return 0;
}
0