HDU1284 錢幣兌換問題,揹包問題

最經典的揹包問題


/*******************************************************************************
 # Author : Neo Fung
 # Email : [email protected]
 # Last modified: 2012-06-13 16:07
 # Filename: acm.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=33000;
const double kEPS=10E-6;

long long dp[kMAX];

int main(void)
{
#ifdef DEBUG  
  freopen("../stdin.txt","r",stdin);
  freopen("../stdout.txt","w",stdout); 
#endif  

  int n;
	memset(dp,0,sizeof(dp));
	dp[0]=1ll;

	for(int i=1;i<=3;++i)
		for(int j=i;j<kMAX;++j)
			dp[j]+=dp[j-i];

  while(~scanf("%d",&n) && n)
  {
		printf("%lld\n",dp[n]);
  }

  return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章