| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:不用背包问题AC,附我的解题方法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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator