結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
19,196 KB
testcase_01 AC 11 ms
23,104 KB
testcase_02 WA -
testcase_03 AC 10 ms
23,104 KB
testcase_04 AC 7 ms
11,384 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 13 ms
23,104 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 65 ms
136,396 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 42 ms
81,704 KB
testcase_25 AC 124 ms
257,500 KB
testcase_26 AC 111 ms
230,156 KB
testcase_27 AC 112 ms
234,064 KB
testcase_28 AC 97 ms
202,808 KB
testcase_29 AC 246 ms
394,236 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 11 ms
19,196 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
 
 
 /*
N≤100
1≤vi,wi≤10001≤vi,wi≤1000
0≤V≤100000
*/

// 番号 重さ = 価値
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 = 1000000;
    cin >> V;
    
    for(int j = 0; j <= 1000000; 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