結果

問題 No.527 ナップサック容量問題
ユーザー NasatameNasatame
提出日時 2017-06-09 22:50:45
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,054 bytes
コンパイル時間 615 ms
コンパイル使用メモリ 58,556 KB
実行使用メモリ 398,200 KB
最終ジャッジ日時 2023-10-23 22:31:17
合計ジャッジ時間 6,027 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
19,256 KB
testcase_01 AC 12 ms
23,164 KB
testcase_02 AC 8 ms
15,356 KB
testcase_03 AC 12 ms
23,164 KB
testcase_04 AC 8 ms
11,444 KB
testcase_05 AC 89 ms
163,808 KB
testcase_06 AC 241 ms
339,604 KB
testcase_07 WA -
testcase_08 AC 71 ms
140,368 KB
testcase_09 AC 9 ms
11,448 KB
testcase_10 WA -
testcase_11 AC 120 ms
241,940 KB
testcase_12 AC 85 ms
175,528 KB
testcase_13 AC 229 ms
351,324 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 13 ms
23,164 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 65 ms
136,456 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 41 ms
81,764 KB
testcase_25 AC 138 ms
257,564 KB
testcase_26 AC 112 ms
230,216 KB
testcase_27 AC 112 ms
234,124 KB
testcase_28 AC 97 ms
202,868 KB
testcase_29 AC 271 ms
394,296 KB
testcase_30 AC 23 ms
42,700 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 12 ms
19,256 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
 

// 番号 重さ = 価値
int dp[101][1000100] = {};
int main(void){
    
    int n;
    cin >> n;
    
    for(int i = 0; i < n; i++)
        for(int j = 0; j < 1000100; j++)
            dp[i][j] = -1;
    
    
    dp[0][0] = 0;
    
    for(int i = 0; i < n; i++){
        int v,w;
        cin >> v >> w;
        
        for(int j = 1000099; j >= 0; j --){
            if(dp[i][j] != -1 && j + w < 1000099){
                dp[i+1][j+w] = v + dp[i][j];
                dp[i+1][j] = dp[i][j];
                //cout << j+w << endl;
            }
        }
    }
    int V,Max = 0,Min = 1000100;
    cin >> V;
    
    
    
    for(int j = 0; j <= 1000100; j++){
        
        dp[n][j+1] = max(dp[n][j+1],dp[n][j]); 
        
        if(dp[n][j] == V){
            Max = max(Max,j);
            Min = min(Min,j);
        }
    }
    
    cout << max(Min,1) << endl;
    if(Max == 1000100) 
    cout << "inf" << endl;
    else 
    cout << Max << endl; 
    
}
0