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 |
算是搜索题吧,先把所以yes的情况找出来#include<iostream> #include<cstring> using namespace std; int a[12]; bool v[6000000]; int sum; int go(int x) { if(x==11) { v[sum]=1; return 0; } sum+=a[x]; go(x+1); sum-=a[x]; go(x+1); return 0; } int main() { memset(v,0,sizeof(v)); a[0]=1; for(int i=1;i<=10;i++)a[i]=a[i-1]*i; sum=0; go(0); int n; while(cin>>n) { if(n<0)return 0; if(v[n]==1&&n!=0)cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator