Submission #44997
ソースコード
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 | #include <bits/stdc++.h> using namespace std; #define FOR(i,n) for(int i=0;i<n;i++) #define why(n,x) int n;while(cin >>n,n!=x) #define iFOR(i,x,n)for(int i=x;i<n;i++) #define unless(flg) if ( !(flg) ) #define read cin<< #define echo cout<< #define fin <<'\n' #define __ <<" "<< #define bash push_back #define alles(x) x.begin(),x.end() #define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b)) int dx[]={1,0,-1,0,1,1,-1,-1}; int dy[]={0,-1,0,1,-1,1,-1,1}; const int INF=1 << 30; bool inside( int x, int y, int w, int h){ return (x>=0 && y>=0 && x<w && y<h);} typedef long long ll; typedef pair< int , int > pii; typedef vector< int > vit; typedef map<string, int > mstit; typedef priority_queue< int > pqit; int dp[105][10005]; int n,wight; int v[10005],w[10005]; int mem[105][10005]; int knap( int pos, int sum){ if (pos == n) return 0; if (sum + w[pos] > wight) return mem[pos][sum] = knap(pos+1 , sum); if (~mem[pos][sum]) return mem[pos][sum]; return mem[pos][sum]=max(knap(pos+1,sum),knap(pos,sum+w[pos])+v[pos]); } int main(){ cin.tie(0), ios::sync_with_stdio( false ); cin >>n>>wight; memset (mem,-1, sizeof (mem)); FOR(i,n) cin >>v[i] >> w[i] ; cout <<knap(0,0) fin; return 0; } |
ステータス
項目 | データ |
---|---|
問題 | 0239 - ナップザック問題(Medium) |
ユーザー名 | ei1821 |
投稿日時 | 2018-11-15 19:02:13 |
言語 | C++14 |
状態 | Accepted |
得点 | 3 |
ソースコード長 | 1235 Byte |
最大実行時間 | 44 ms |
最大メモリ使用量 | 7292 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 3 / 3 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
DPL_1_C_in1.txt | AC | 44 ms | 6748 KB |
1
|
DPL_1_C_in2.txt | AC | 30 ms | 6684 KB |
1
|
DPL_1_C_in3.txt | AC | 33 ms | 6892 KB |
1
|
DPL_1_C_in4.txt | AC | 24 ms | 6916 KB |
1
|
DPL_1_C_in5.txt | AC | 24 ms | 6888 KB |
1
|
DPL_1_C_in6.txt | AC | 24 ms | 6984 KB |
1
|
DPL_1_C_in7.txt | AC | 22 ms | 6816 KB |
1
|
DPL_1_C_in8.txt | AC | 29 ms | 6908 KB |
1
|
DPL_1_C_in9.txt | AC | 33 ms | 7004 KB |
1
|
DPL_1_C_in10.txt | AC | 34 ms | 6840 KB |
1
|
DPL_1_C_in11.txt | AC | 17 ms | 6796 KB |
1
|
DPL_1_C_in12.txt | AC | 29 ms | 6608 KB |
1
|
DPL_1_C_in13.txt | AC | 28 ms | 6700 KB |
1
|
DPL_1_C_in14.txt | AC | 23 ms | 6668 KB |
1
|
DPL_1_C_in15.txt | AC | 31 ms | 6628 KB |
1
|
DPL_1_C_in16.txt | AC | 41 ms | 6588 KB |
1
|
DPL_1_C_in17.txt | AC | 33 ms | 6668 KB |
1
|
DPL_1_C_in18.txt | AC | 31 ms | 6760 KB |
1
|
DPL_1_C_in19.txt | AC | 25 ms | 6848 KB |
1
|
DPL_1_C_in20.txt | AC | 23 ms | 6780 KB |
1
|
DPL_1_C_in21.txt | AC | 22 ms | 6740 KB |
1
|
DPL_1_C_in22.txt | AC | 26 ms | 6700 KB |
1
|
DPL_1_C_in23.txt | AC | 26 ms | 6672 KB |
1
|
DPL_1_C_in24.txt | AC | 38 ms | 6760 KB |
1
|
DPL_1_C_in25.txt | AC | 24 ms | 6852 KB |
1
|
DPL_1_C_in26.txt | AC | 26 ms | 6940 KB |
1
|
DPL_1_C_in27.txt | AC | 22 ms | 6740 KB |
1
|
DPL_1_C_in28.txt | AC | 31 ms | 6832 KB |
1
|
DPL_1_C_in29.txt | AC | 23 ms | 6796 KB |
1
|
DPL_1_C_in30.txt | AC | 22 ms | 6856 KB |
1
|
DPL_1_C_in31.txt | AC | 21 ms | 6824 KB |
1
|
DPL_1_C_in32.txt | AC | 31 ms | 6784 KB |
1
|
DPL_1_C_in33.txt | AC | 33 ms | 6872 KB |
1
|
DPL_1_C_in34.txt | AC | 32 ms | 6704 KB |
1
|
DPL_1_C_in35.txt | AC | 25 ms | 6796 KB |
1
|
DPL_1_C_in36.txt | AC | 41 ms | 6884 KB |
1
|
DPL_1_C_in37.txt | AC | 36 ms | 6848 KB |
1
|
DPL_1_C_in38.txt | AC | 44 ms | 6812 KB |
1
|
DPL_1_C_in39.txt | AC | 25 ms | 7292 KB |
1
|
DPL_1_C_in40.txt | AC | 29 ms | 7264 KB |
1
|