题目就是要我们将一个数表示成阶乘和的形式,用的好像是打表的方法吧。地址:
http://acm.pku.edu.cn/JudgeOnline/problem?id=1775
#include <stdio.h>
const int MAXLEN = 1000001;
int num[10] = { 1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880 };
char dp[MAXLEN][10];
void cup ()
{
int i;
for ( i=0; i<10; i++ )
{
dp[0][i] = 0;
}
for ( i=1; i<MAXLEN; i++ )
{
for ( int j=0; j<10; j++ )
{
dp[i][j] = 0;
int next = i - num[j];
if ( next == 0 )
{
dp[i][j] = 1;
}
else
{
if ( next > 0 )
{
for ( int z=0; z<j; z++ )
{
if ( dp[next][z] )
{
dp[i][j] = dp[next][z];
break;
}
}
}
}
}
}
}
int main ()
{
int n;
cup ();
while ( scanf ( "%d", &n ) != EOF && (n >= 0) )
{
int i;
for ( i=0; i<10; i++ )
{
if ( dp[n][i] )
{
printf ( "YES\n" );
break;
}
}
if ( i >= 10 )
{
printf ( "NO\n" );
}
}
return 0;
}