刚那到题目时以为是搜索题,分析一下又觉得是动归或者记忆化搜索...
其实都不是的,是一道白痴题.
题目中的陷阱很多, 做男人就是不容易啊,没有女孩子细心,我竟然为它的每一个陷阱都贡献了一个以上WA..
以下是题目中较生猛陷阱,需要细心的:
.
The input is terminated by a line with a negative integer (习惯上会认为以-1结束)
For a given n, you'll check if there are some xi, and let n equal to Σ1<=i<=txi!. (t >=1 1, xi >= 0, xi = xj iff. i = j). 这个条件..太强悍了..关于0时是YES还是NO的问题,我贡献了3个WA才看清!
代码如下
:
#include"stdio.h"



int fun(int x)


{

int temp=1;
int y=1;
while(y<=x)

{
temp=temp*y;
y++;
}
return temp;

}

void main()


{

int n;
int i;
int a[12];


for(i=0;i<=11;i++)
a[i]=fun(i);

while(1)

{
scanf("%d",&n);

if(n==0)
{printf("NO\n");continue;}
if(n<0)return;
i=11;
while(i>=0&&n>=0)

{
if(n>=a[i])n=n-a[i];
i--;
}
if(n==0)printf("YES\n");
else printf("NO\n");



}
return ;
}
