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 |
141MS险过,谨记1!+2!+......n!<(n+1)!就行!虽然一次AC,但效率不高,贴上代码仅供参考,如有优化感激不尽#include <stdio.h> int find(int n) { if(n==0) return 1; else return n*find(n-1); } int solve(int n,int k) { int i,flag=0; for(i=9; i>=0; i--) { if(n==find(i)&&i<k) { flag=1; break; } else if(n>find(i)&&i<k) { k=i; break; } } if(flag==0&&k>0) solve(n-find(k),k); else return flag; } int main() { int n,i; while(scanf("%d",&n),n>=0) { if(solve(n,10)==1) 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