Submission #41368
ソースコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | #include <iostream> #include <string> #include <stack> #include <queue> #include <cstring> #include <algorithm> #include <vector> //#include <cstdio> #include <cmath> #include <cstdlib> #include <functional> #include <map> #include <numeric> using namespace std; #define elif else if #define echo cout << #define read cin >> #define fin << '\n' #define finn cout << '\n' #define forin(i, n) for ( int i = 0; i < n; i++ ) #define unless(flg) if(!(flg)) #define zu >> #define und << #define alles(obj) obj.begin(), obj.end() #define bash push_back #define makePair make_pair // type-define #define String string #define Stack stack #define Queue queue #define pQueue priority_queue #define Vector vector #define Pair pair #define Map map typedef long long llong; typedef bool boolean; typedef Pair< int , int > Pii; typedef Vector< int > Vi; // utils const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1}; const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1}; boolean canMove( int x, int y, int w, int h){ return (x>=0&&y>=0&&x<w&&y<h);}; const int INF = 1 << 29; int cnt = 0; int N, W; int v[110], w[110]; int dp[1010][10100]; int rec( int pos, int weight){ unless ( dp[pos][weight] == -1 ) return dp[pos][weight]; if ( pos == N ) return 0; if ( weight-w[pos] < 0 ) return dp[pos][weight] = rec(pos+1, weight); return dp[pos][weight] = max(max(rec(pos+1, weight-w[pos]) + v[pos], rec(pos+1, weight)), rec(pos, weight-w[pos]) + v[pos]); } int main(){ cin.tie(0); ios::sync_with_stdio( false ); read N >> W; for ( int i = 0; i < N; i++ ) { read v[i] >> w[i]; } memset (dp, -1, sizeof (dp)); echo rec(0, W) fin; return 0; } |
ステータス
項目 | データ |
---|---|
問題 | 0239 - ナップザック問題(Medium) |
ユーザー名 | r1825 |
投稿日時 | 2018-08-21 06:29:57 |
言語 | C++14 |
状態 | Accepted |
得点 | 3 |
ソースコード長 | 1718 Byte |
最大実行時間 | 40 ms |
最大メモリ使用量 | 41112 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 3 / 3 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
DPL_1_C_in1.txt | AC | 26 ms | 40288 KB |
1
|
DPL_1_C_in2.txt | AC | 28 ms | 40516 KB |
1
|
DPL_1_C_in3.txt | AC | 34 ms | 40640 KB |
1
|
DPL_1_C_in4.txt | AC | 27 ms | 40564 KB |
1
|
DPL_1_C_in5.txt | AC | 22 ms | 40452 KB |
1
|
DPL_1_C_in6.txt | AC | 26 ms | 40500 KB |
1
|
DPL_1_C_in7.txt | AC | 34 ms | 40552 KB |
1
|
DPL_1_C_in8.txt | AC | 31 ms | 40596 KB |
1
|
DPL_1_C_in9.txt | AC | 34 ms | 40640 KB |
1
|
DPL_1_C_in10.txt | AC | 28 ms | 40464 KB |
1
|
DPL_1_C_in11.txt | AC | 30 ms | 40252 KB |
1
|
DPL_1_C_in12.txt | AC | 24 ms | 40404 KB |
1
|
DPL_1_C_in13.txt | AC | 30 ms | 40328 KB |
1
|
DPL_1_C_in14.txt | AC | 21 ms | 40376 KB |
1
|
DPL_1_C_in15.txt | AC | 40 ms | 40420 KB |
1
|
DPL_1_C_in16.txt | AC | 35 ms | 40332 KB |
1
|
DPL_1_C_in17.txt | AC | 25 ms | 40368 KB |
1
|
DPL_1_C_in18.txt | AC | 35 ms | 40416 KB |
1
|
DPL_1_C_in19.txt | AC | 23 ms | 40468 KB |
1
|
DPL_1_C_in20.txt | AC | 27 ms | 40444 KB |
1
|
DPL_1_C_in21.txt | AC | 35 ms | 40364 KB |
1
|
DPL_1_C_in22.txt | AC | 27 ms | 40284 KB |
1
|
DPL_1_C_in23.txt | AC | 34 ms | 40332 KB |
1
|
DPL_1_C_in24.txt | AC | 30 ms | 40384 KB |
1
|
DPL_1_C_in25.txt | AC | 32 ms | 40308 KB |
1
|
DPL_1_C_in26.txt | AC | 30 ms | 40356 KB |
1
|
DPL_1_C_in27.txt | AC | 24 ms | 40368 KB |
1
|
DPL_1_C_in28.txt | AC | 25 ms | 40412 KB |
1
|
DPL_1_C_in29.txt | AC | 22 ms | 40588 KB |
1
|
DPL_1_C_in30.txt | AC | 29 ms | 40432 KB |
1
|
DPL_1_C_in31.txt | AC | 25 ms | 40344 KB |
1
|
DPL_1_C_in32.txt | AC | 30 ms | 40520 KB |
1
|
DPL_1_C_in33.txt | AC | 33 ms | 40572 KB |
1
|
DPL_1_C_in34.txt | AC | 38 ms | 40492 KB |
1
|
DPL_1_C_in35.txt | AC | 27 ms | 40416 KB |
1
|
DPL_1_C_in36.txt | AC | 31 ms | 40460 KB |
1
|
DPL_1_C_in37.txt | AC | 29 ms | 40508 KB |
1
|
DPL_1_C_in38.txt | AC | 35 ms | 40424 KB |
1
|
DPL_1_C_in39.txt | AC | 34 ms | 41112 KB |
1
|
DPL_1_C_in40.txt | AC | 31 ms | 40868 KB |
1
|