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 |
G++过不了,,C++神奇过了。。#include <iostream> #include <cstdio> using namespace std; int s[10]={1,1,2,6,24,120,720,5040,40320,362880}; int sum; int n; int temp; int dfs(int a) { for(int j=a;j<=9;j++) { sum=sum+s[j]; if(sum==n) { temp=1; return 1; } dfs(j+1); if(temp==1) return 1; sum=sum-s[j]; } } int main() { int tem; while( cin>>n && n>-1){ sum=0; temp=0; if(n == 0) { printf("NO\n"); continue; } tem=dfs(0); if(tem==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