From 74f43c6ec708480857d0e358eed0b6bf6624a697 Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Thu, 1 Sep 2016 20:32:53 +0800 Subject: [PATCH] Create 1276_libin56842.cpp --- POJ/1276_libin56842.cpp | 55 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 POJ/1276_libin56842.cpp diff --git a/POJ/1276_libin56842.cpp b/POJ/1276_libin56842.cpp new file mode 100644 index 0000000..42695db --- /dev/null +++ b/POJ/1276_libin56842.cpp @@ -0,0 +1,55 @@ +#include +#include +#include +using namespace std; + +struct node +{ + int n,v; +} a[20]; + +int dp[100010]; + +int main() +{ + int sum,n,i,j,k; + while(~scanf("%d%d",&sum,&n)) + { + for(i = 1; i<=n; i++) + scanf("%d%d",&a[i].n,&a[i].v); + if(!sum) + { + printf("0\n"); + continue; + } + if(!n) + { + printf("0\n"); + continue; + } + memset(dp,0,sizeof(dp)); + dp[0] = 1; + int MAX = 0,tem; + for(i = 1; i<=n; i++) + { + for(j = MAX;j>=0;j--) + { + if(dp[j]) + { + for(k = 1;k<=a[i].n;k++) + { + tem = j+k*a[i].v; + if(tem>sum) + continue; + dp[tem] = 1; + if(tem>MAX) + MAX = tem; + } + } + } + } + printf("%d\n",MAX); + } + + return 0; +}