From 8983f81bfee0f5e9b2f79c9941f0fe95c4cac266 Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Sun, 22 May 2016 16:20:35 +0800 Subject: [PATCH] Create 1276_funCfans.cpp From http://poj.org/showmessage?message_id=346125 --- POJ/1276_funCfans.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 POJ/1276_funCfans.cpp diff --git a/POJ/1276_funCfans.cpp b/POJ/1276_funCfans.cpp new file mode 100644 index 0000000..985b577 --- /dev/null +++ b/POJ/1276_funCfans.cpp @@ -0,0 +1,58 @@ +#include +#include +#include +struct q +{ + int a,p; +}; +int cmp(const void *a,const void *b) +{ + return (*(q*)a).p-(*(q*)b).p; +} +int main() +{ + q qs[11]; + int cash,n,i,j,con[100001]; + char dp[100001]; + while(scanf("%d%d",&cash,&n)==2) + { + if(!n) + { + putchar('0');putchar('\n'); + continue; + } + for(i=0;i=qs[i].p;j--) + { + if(dp[j]) + { + if(con[j] && !dp[j-qs[i].p]) + { + con[j-qs[i].p]=con[j]-1; + dp[j-qs[i].p]=1; + } + con[j]=qs[i+1].a; + } + } + } + for(i=0;!dp[i];i++); + printf("%d\n",cash-i); + } + return 0; +}