結果

問題 No.527 ナップサック容量問題
ユーザー ttakanottakano
提出日時 2017-12-02 12:12:44
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,129 bytes
コンパイル時間 1,254 ms
コンパイル使用メモリ 158,696 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-05-06 01:41:35
合計ジャッジ時間 5,728 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
10,752 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 TLE -
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 TLE -
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 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define printall(n,array) for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<int, PI> V;
typedef vector<int> VE;
const ll mod = 1000000007; //10^9+7

int dp[102][100003];

int main(){
  int n;  cin>>n;
  int w[1002];
  int v[1002];
  int sum_w=0;
  int sum_v=0;
  REP(i,n){
    cin>>v[i]>>w[i];
    sum_v+=v[i];
    sum_w+=w[i];
  }
  int V; cin>>V;
  if(sum_v==V){
    print(sum_w);
    print("inf");
    return 0;
  }
  int max_=0,min_=mod;
  REP(W,100002){
    //print(W);
    REP(i,n+1)REP(j,W+2)dp[i][j]=0;
    for(int i=n-1;i>=0;i--){
      REP(j,W+1){
        if(j<w[i]){
          dp[i][j]=dp[i+1][j];
        }else{
          dp[i][j]=max(dp[i+1][j],dp[i+1][j-w[i]]+v[i]);
        }
      }
    }
    if(dp[0][W]>V)break;
    if(dp[0][W]==V){
      max_=max(max_,W);
      min_=min(min_,W);
      //print("max "<<max_<<" min "<<min_);
    }
  }
  min_=min_==0?1:min_;
  print(min_);
  print(max_);
}
0