結果
| 問題 | No.527 ナップサック容量問題 |
| コンテスト | |
| ユーザー |
rodea
|
| 提出日時 | 2018-03-02 18:46:24 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 765 bytes |
| 記録 | |
| コンパイル時間 | 491 ms |
| コンパイル使用メモリ | 68,384 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-11 19:11:56 |
| 合計ジャッジ時間 | 1,517 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 14 WA * 23 |
ソースコード
#include<iostream>
#include<algorithm>
#include<utility>
using namespace std;
int v[110], w[110];
int dp[110][1010];
pair<int, int> solve(int n, int V, pair<int, int>P)
{
P = make_pair(1000000, 0);
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= 1001; j++)
{
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[i][j] == V)
{
P.first = min(P.first, j);
P.second = max(P.second, j);
}
}
}
return P;
}
int main()
{
int n, V;
pair<int, int> P;
cin >> n;
for (int i = 1; i <= n; i++) cin >> v[i] >> w[i];
cin >> V;
cout << solve(n, V, P).first << endl;
if(solve(n, V, P).second != 1010) cout << solve(n, V, P).second << endl;
else cout << "inf" << endl;
}
rodea