题解 | #Sum of Factorials#

Sum of Factorials

https://www.nowcoder.com/practice/42cb1c7f7344466b8cb1710cb12d06b1

#include<bits/stdc++.h>
using namespace std;
int jie(int x){
    int n=x;
    if(x==0) return 1;
    while(n>1){
        n--;
        x=x*n;
    }
    
    return x;
}
int dfs(int x,int sum,int n){
    if(sum==x) return 1;
    if(n==10)
    return -1;
    n++;
    return max(dfs(x,sum+jie(n),n),dfs(x,sum,n));
}

int main(){
    int x;
    while(cin>>x){
        if(x<0) break;
        if(x==0) {cout<<"NO"<<endl;continue;}
        int sum=0;int flag=0;
        flag=dfs(x,sum,-1);
        if(flag==1)
        cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
        
    }
    
    
    
    return 0;
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-10 11:33
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-09 12:02
ssob上原来真有BOSS啊
硫蛋蛋:这种也是打工的,只不是是给写字楼房东打工
点赞 评论 收藏
分享
07-07 12:47
门头沟学院 Java
码农索隆:竟然还真有卡体检报告的
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-07 18:05
哈哈哈哈哈感觉朋友找工作的已经疯掉了,直接上图
码农索隆:真老板娘:“我嘞个去,这不我当年的套路吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务