Submission #1531189
Source Code Expand
#define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<cstdio> #include<string> #include<algorithm> #include<cmath> using namespace std; #define REP(i,n) for(int i=0;(i)<(n);(i)++) int dp[102][10004]; int knapsack(int N, int W, int v[], int w[]) { //int dp[102][10004]; REP(i, N + 1) { REP(j, W + 1) dp[i][j] = -1;//初期化 } REP(i, N + 1) dp[i][0] = 0; //ナップザックの大きさが0なら価値の最大は0 REP(j, W + 1) dp[0][j] = 0; //品物の数が0なら価値の最大は0 int dia, top; for (int i = 1;i <= N;i++) { for (int j = 1;j <= W;j++) { if (j - w[i] >= 0) dia = dp[i - 1][j - w[i]] + v[i];//i番目の品物を選んだ時 else dia = 0; top = dp[i - 1][j];//i番目の品物を選ばなかったとき dp[i][j] = max(dia, top); } } return dp[N][W]; } int main() { int N, W; cin >> N >> W; int v[102], w[102]; for (int i = 1; i <= N; i++) {//1-origin cin >> w[i] >> v[i]; } int ans = knapsack(N, W, v, w); cout << ans << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Simple Knapsack |
User | takiteke |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1065 Byte |
Status | RE |
Exec Time | 98 ms |
Memory | 4224 KB |
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 400 | ||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | example0, example1, example2, example3 |
All | antigreedy0, antigreedy1, antigreedy2, example0, example1, example2, example3, quarter0, quarter1, quarter2, rand0, rand1, rand2, smallw0, smallw1, smallw2 |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
antigreedy0 | RE | 98 ms | 4224 KB |
antigreedy1 | RE | 97 ms | 4224 KB |
antigreedy2 | RE | 97 ms | 4224 KB |
example0 | AC | 1 ms | 256 KB |
example1 | AC | 1 ms | 256 KB |
example2 | AC | 1 ms | 256 KB |
example3 | AC | 1 ms | 256 KB |
quarter0 | AC | 3 ms | 2304 KB |
quarter1 | AC | 3 ms | 2176 KB |
quarter2 | AC | 2 ms | 1152 KB |
rand0 | RE | 97 ms | 4224 KB |
rand1 | RE | 98 ms | 4224 KB |
rand2 | RE | 98 ms | 4224 KB |
smallw0 | AC | 2 ms | 1024 KB |
smallw1 | AC | 2 ms | 1024 KB |
smallw2 | AC | 1 ms | 768 KB |