虽然有些变化,但是只要理解清楚母函数的定义,就很容易搞定了。
/******************************************************************************* # Author : Neo Fung # Email : [email protected] # Last modified: 2012-06-26 19:44 # Filename: HDU1085 Holding Bin-Laden Captive!.cpp # Description : ******************************************************************************/ #ifdef _MSC_VER #define DEBUG #define _CRT_SECURE_NO_DEPRECATE #endif #include <fstream> #include <stdio.h> #include <iostream> #include <string.h> #include <string> #include <limits.h> #include <algorithm> #include <math.h> #include <numeric> #include <functional> #include <ctype.h> using namespace std; const int kMAX=10010; const double kEPS=10E-6; int main(void) { #ifdef DEBUG freopen("../stdin.txt","r",stdin); freopen("../stdout.txt","w",stdout); #endif int n,num[4],value[4]={0,1,2,5}; int ans[kMAX],tans[kMAX]; while(~scanf("%d%d%d",&num[1],&num[2],&num[3]) && (num[1]+num[2]+num[3])) { memset(tans,0,sizeof(tans)); memset(ans,0,sizeof(ans)); fill(ans,ans+num[1]+1,1); for(int i=2;i<=3;++i) { for(int j=0;j<kMAX;++j) if(ans[j]) { for(int k=0,remain=num[i]+1;k+j<=kMAX && remain;k+=value[i],--remain) //这里remain=num[i]+1,是因为k是从0开始,而不是从value[i]开始 tans[k+j]+=ans[j]; } memcpy(ans,tans,sizeof(tans)); memset(tans,0,sizeof(tans)); } int tmp=1; while(ans[tmp]) ++tmp; printf("%d\n",tmp); } return 0; }