結果

問題 No.527 ナップサック容量問題
ユーザー YamyukiYamyuki
提出日時 2017-06-09 23:29:31
言語 C90
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 615 bytes
コンパイル時間 675 ms
コンパイル使用メモリ 22,192 KB
実行使用メモリ 79,544 KB
最終ジャッジ日時 2023-10-24 02:21:46
合計ジャッジ時間 2,458 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
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 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:7:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    7 |         scanf("%d",&n);
      |         ^~~~~~~~~~~~~~
main.c:9:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |                 scanf("%ld %ld",&v[i],&w[i]);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.c:11:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |         scanf("%ld",&V);
      |         ^~~~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>
#define max(a,b) (((a)>(b))?(a):(b))
long dp[100][100001],v[100],w[100];
int main(int argc, char const *argv[]){
	int n,i,f=0;
	long V,j;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%ld %ld",&v[i],&w[i]);
	}
	scanf("%ld",&V);
	for(j=w[0];j<=100000;j++){
		dp[0][j]=v[i];
	}
	for(i=1;i<n;i++){
		for(j=0;j<=100000;j++){
			if(j+w[i]<=100000) dp[i][j+w[i]]=max(dp[i-1][j+w[i]],dp[i-1][j]+v[i]);
		}
	}
	for(j=0;j<=100000;j++){
		if(f==0 && dp[n-1][j]==V){
			printf("%ld\n",j);
			f=1;
		}else if(f==1 && dp[n-1][j]>V){
			f=2;
			printf("%ld\n",j-1);
		}
	}
	if(f==1) printf("inf\n");
	return 0;
}
0