题目链接
按照01背包的思路,由于数据量较小,直接用深搜搞!

#include<bits/stdc++.h>
using namespace std;
int A[10]={1,1,2,6,24,120,720,5040,40320,362880};
int n,ans; 
void dfs(int index,int sum){
	if(index==10) return;
	dfs(index+1, sum);
	if(sum + A[index] == n){
		ans=1;
		return;
	}else if(sum + A[index] < n){
		dfs(index+1, sum + A[index]);
	}
}
int main(){	
	while(cin>>n){
		ans=0;
		dfs(0, 0);
		if(ans==0) cout<<"NO"<<endl;
		else cout<<"YES"<<endl;
	}
	return 0;
}