結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
19,272 KB
testcase_01 AC 11 ms
23,180 KB
testcase_02 AC 9 ms
15,372 KB
testcase_03 AC 11 ms
23,180 KB
testcase_04 AC 8 ms
11,460 KB
testcase_05 AC 111 ms
163,824 KB
testcase_06 AC 300 ms
339,620 KB
testcase_07 WA -
testcase_08 AC 69 ms
140,384 KB
testcase_09 AC 8 ms
11,464 KB
testcase_10 WA -
testcase_11 AC 116 ms
241,956 KB
testcase_12 AC 88 ms
175,544 KB
testcase_13 AC 223 ms
351,340 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 13 ms
23,180 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 65 ms
136,472 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 43 ms
81,780 KB
testcase_25 AC 129 ms
257,580 KB
testcase_26 AC 110 ms
230,232 KB
testcase_27 AC 112 ms
234,140 KB
testcase_28 AC 98 ms
202,884 KB
testcase_29 AC 262 ms
394,312 KB
testcase_30 AC 24 ms
42,716 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 11 ms
19,272 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 = 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 > 1000000) 
    cout << "inf" << endl;
    else 
    cout << Max << endl; 
    
}
0