HDU1085 Holding Bin-Laden Captive!,모함수

1630 단어 email
비록 약간의 변화가 있지만 모함수의 정의를 똑똑히 이해하면 쉽게 해결할 수 있다.
/*******************************************************************************
 # 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
",tmp); } return 0; }

좋은 웹페이지 즐겨찾기