Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:不用背包问题AC,附我的解题方法

Posted by zihuacs at 2010-08-18 17:21:00 on Problem 1775
In Reply To:Re:不用背包问题AC,附我的解题方法 Posted by:zihuacs at 2010-08-18 17:20:18
按照你的思路写的代码
#include <iostream>
using namespace std;
int fact[10];
int n;
inline void Init(void)
{
	fact[0]=1;
	for(int i=1; i<10; i++)
	{
		fact[i]=fact[i-1]*i;
	}
}
inline bool Solve(void)
{
	if(n==0)
		return false;
	int i;
	for(i=9; i>=0; i--)
	{
		if(n>=fact[i])
			n-=fact[i];
	}
	return n==0 ? true : false;
}
int main(void)
{
	Init();
	while(scanf("%d",&n))
	{
		if(n<0)
			break;
		if(Solve())
		{
			printf("YES\n");
		}
		else
		{
			printf("NO\n");
		}
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator