Submission #45015
ソースコード
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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | // to Utils -> L47 // to Rlyeh -> L78 #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 class struct #define constexpr const #define bogo_sort sort #define bozo_sort stable_sort #define elif else if #define echo cout << #define read cin >> #define fin << '\n' #define unless(flg) if(!(flg)) #define elless(flg) else if(!(flg)) #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 constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1}; constexpr int dy[] = {0, 1, 0, -1, 1, -1, 1, -1}; constexpr int INF = 1 << 29; class Utils { static llong power ( llong x, llong n, llong mod ) { llong ans = 1; while ( n > 0 ) { if ( n & 1 ) { ans = ( ans * x ) % mod; } x = ( x * x ) % mod; n >>= 1; } return ans; } static llong power ( llong x, llong n ) { return power( x, n, 1000000007 ); } static llong gcd ( llong x, llong y ) { return x % y ? gcd( y, x % y ) : y; } static llong lcm ( llong x, llong y ) { return ( x / gcd(x, y) * y ); } static boolean isMovable ( int x, int y, int w, int h ) { return ( x >= 0 && y >= 0 && x < w && y < h ); } }; namespace Rlyeh { int max ( int a, int b, int c ) { return std::max ( a, std::max ( b, c ) ); } struct Hori { int v, w; } ; int n, w; Hori hori[110]; int dp[110][10010]; int dfs ( int pos, int sum ) { if ( ~dp[pos][sum] ) return dp[pos][sum]; elif ( pos == n ) return 0; elif ( sum + hori[pos].w > w ) { return dp[pos][sum] = dfs ( pos + 1, sum ); } else { return dp[pos][sum] = max ( dfs(pos+1, sum), dfs(pos, sum+hori[pos].w) + hori[pos].v, dfs(pos+1, sum+hori[pos].w) + hori[pos].v ); } } signed call_of_Cthulhu( signed datum ) { read n >> w; for ( int i = 0; i < n; i++ ) { read hori[i].v >> hori[i].w; } memset (dp, -1, sizeof (dp)); echo dfs(0, 0) fin; return 0; } } signed main(){cin.tie(0); ios::sync_with_stdio( false ); Rlyeh::call_of_Cthulhu(114514); return 0;} |
ステータス
項目 | データ |
---|---|
問題 | 0239 - ナップザック問題(Medium) |
ユーザー名 | r1825 |
投稿日時 | 2018-11-16 07:14:05 |
言語 | C++14 |
状態 | Accepted |
得点 | 3 |
ソースコード長 | 2799 Byte |
最大実行時間 | 39 ms |
最大メモリ使用量 | 5524 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 3 / 3 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
DPL_1_C_in1.txt | AC | 27 ms | 4956 KB |
1
|
DPL_1_C_in2.txt | AC | 22 ms | 4992 KB |
1
|
DPL_1_C_in3.txt | AC | 28 ms | 4816 KB |
1
|
DPL_1_C_in4.txt | AC | 31 ms | 5072 KB |
1
|
DPL_1_C_in5.txt | AC | 21 ms | 5004 KB |
1
|
DPL_1_C_in6.txt | AC | 34 ms | 5016 KB |
1
|
DPL_1_C_in7.txt | AC | 33 ms | 5020 KB |
1
|
DPL_1_C_in8.txt | AC | 24 ms | 5032 KB |
1
|
DPL_1_C_in9.txt | AC | 29 ms | 4912 KB |
1
|
DPL_1_C_in10.txt | AC | 23 ms | 4960 KB |
1
|
DPL_1_C_in11.txt | AC | 23 ms | 4828 KB |
1
|
DPL_1_C_in12.txt | AC | 21 ms | 4816 KB |
1
|
DPL_1_C_in13.txt | AC | 29 ms | 4816 KB |
1
|
DPL_1_C_in14.txt | AC | 27 ms | 4920 KB |
1
|
DPL_1_C_in15.txt | AC | 20 ms | 4924 KB |
1
|
DPL_1_C_in16.txt | AC | 26 ms | 5268 KB |
1
|
DPL_1_C_in17.txt | AC | 35 ms | 5164 KB |
1
|
DPL_1_C_in18.txt | AC | 21 ms | 4984 KB |
1
|
DPL_1_C_in19.txt | AC | 24 ms | 4988 KB |
1
|
DPL_1_C_in20.txt | AC | 21 ms | 4876 KB |
1
|
DPL_1_C_in21.txt | AC | 26 ms | 4884 KB |
1
|
DPL_1_C_in22.txt | AC | 31 ms | 4892 KB |
1
|
DPL_1_C_in23.txt | AC | 25 ms | 4884 KB |
1
|
DPL_1_C_in24.txt | AC | 32 ms | 4844 KB |
1
|
DPL_1_C_in25.txt | AC | 38 ms | 4836 KB |
1
|
DPL_1_C_in26.txt | AC | 32 ms | 4956 KB |
1
|
DPL_1_C_in27.txt | AC | 29 ms | 4788 KB |
1
|
DPL_1_C_in28.txt | AC | 20 ms | 4800 KB |
1
|
DPL_1_C_in29.txt | AC | 25 ms | 4812 KB |
1
|
DPL_1_C_in30.txt | AC | 21 ms | 4828 KB |
1
|
DPL_1_C_in31.txt | AC | 25 ms | 4944 KB |
1
|
DPL_1_C_in32.txt | AC | 31 ms | 4840 KB |
1
|
DPL_1_C_in33.txt | AC | 39 ms | 4852 KB |
1
|
DPL_1_C_in34.txt | AC | 37 ms | 4976 KB |
1
|
DPL_1_C_in35.txt | AC | 34 ms | 4980 KB |
1
|
DPL_1_C_in36.txt | AC | 22 ms | 4852 KB |
1
|
DPL_1_C_in37.txt | AC | 37 ms | 4864 KB |
1
|
DPL_1_C_in38.txt | AC | 37 ms | 4872 KB |
1
|
DPL_1_C_in39.txt | AC | 36 ms | 5524 KB |
1
|
DPL_1_C_in40.txt | AC | 34 ms | 5460 KB |
1
|