結果

問題 No.54 Happy Hallowe'en
ユーザー ss_koishiss_koishi
提出日時 2014-11-06 16:52:35
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 737 bytes
コンパイル時間 1,938 ms
コンパイル使用メモリ 72,832 KB
実行使用メモリ 7,780 KB
最終ジャッジ日時 2023-08-30 01:36:55
合計ジャッジ時間 8,451 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 TLE -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#define INF (2 << 24)
using namespace std;

int n;
int dp[10001];
bool chk[10001];
vector <pair<int, int> > vt;

int rec(int sum){

  if(dp[sum]) return dp[sum];
  int ret = 0;
  for(int i = 0; i < n; i++){
    if(sum < vt[i].second && chk[i]){
      chk[i] = false;
      ret = max(ret, rec(sum + vt[i].first) + vt[i].first);
      chk[i] = true;
    }
  }
  return dp[sum] = ret;
}
    
int main(){
  
  cin >> n;
  for(int i = 0; i < n; i++){
    int v, t; cin >> v >> t;
    vt.push_back(make_pair(v, t));
  }
  sort(vt.begin(), vt.end());
  memset(chk, true, sizeof(chk));
  cout << rec(0) << endl;
}
0