From ab284aeff0a5f4cfe2fcc27557536c9e0f8d8186 Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Sun, 22 May 2016 14:28:51 +0800 Subject: [PATCH] Create 3624.cpp --- POJ/3624.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 POJ/3624.cpp diff --git a/POJ/3624.cpp b/POJ/3624.cpp new file mode 100644 index 0000000..60786a6 --- /dev/null +++ b/POJ/3624.cpp @@ -0,0 +1,44 @@ +#include +#include +#include +#include +using namespace std; + +namespace Package1_SpaceOptimized +{ + const int MAXM = 12880 + 5; + const int MAXN = 3402 + 5; + int ldp[MAXM]; + int w[MAXN]; + int v[MAXN]; + int N,M; + void solve() + { + for(int i=1;i<=N;i++) + { + for(int j=M;j>=1;j--) + { + int a=ldp[j]; + int b=-1; + if(j-w[i]>=0) b=ldp[j-w[i]]+v[i]; + ldp[j]=max(a,b); + } + } + printf("%d\n",ldp[M]); + } + int main() + { + scanf("%d %d",&N,&M); + for(int i=1;i<=N;i++) + { + scanf("%d %d",&w[i],&v[i]); + } + solve(); + return 0; + } +} + +int main() +{ + return Package1_SpaceOptimized::main(); +}