markdown 在线制作ppt json校验和格式化工具

POJ 1775

#include <iostream>
using namespace std;

int fact[] = {1,1,2,6,24,120,720,5040,40320,362880};

bool boo;

void DFS(int time,int sum);

int n;

int main()
{
    //freopen("acm.acm","r",stdin);
    
    while(cin>>n)
    {
        if(n < 0)
        {
            break;
        }
        boo = false;
        DFS(0,0);
        if(boo)
        {
            cout<<"YES"<<endl;
        }
        else
        {
            cout<<"NO"<<endl;
        }
    }

}    

void DFS(int time,int sum)
{
    if(time == 10)
    {
        return;
    }
    sum += fact[time];
    if(sum == n)
    {
        boo = true;
        return;
    }
    else if(sum > n)
    {
        return;
    }
    else if(sum < n)
    {
        DFS(time+1,sum);
        if(boo)
            return;
    }
    sum -= fact[time];
    DFS(time+1,sum);
}

 

关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。 

技术网站地址: vmfor.com

posted @ 2015-06-10 16:44  GavinHacker  阅读(183)  评论(0编辑  收藏  举报
markdown 在线制作ppt json校验和格式化工具