POJ1775

简介:

差一点用DP做了 注意0的阶乘是1 总觉得思维不够开阔 这题问一个非负数是否是不同的数的阶乘组成的 可以循环一遍

就出结果的 从大到小循环。。

#include <iostream>
#include<cstdio>
using namespace std;

int main()
{
    int a[10],n;
    a[0]=1;
    for(int i=1; i<=9; i++)
        a[i]=a[i-1]*i;
    while(~scanf("%d",&n)&&n>=0)
    {
        if(n==0)
        {
            cout<<"NO"<<endl;
            continue;
        }
        for(int i=9; i>=0; i--)
            if(n>=a[i])
                n-=a[i];
        if(n==0)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
    return 0;
}


目录
相关文章
|
6天前
|
算法
Wormholes—POJ3259
Wormholes—POJ3259
|
8月前
|
人工智能
POJ 3104 Drying
POJ 3104 Drying
|
算法框架/工具
POJ 2262 Goldbach's Conjecture
POJ 2262 Goldbach's Conjecture
116 0
POJ 2027 No Brainer
POJ 2027 No Brainer
84 0
F-POJ-3414 Pots
POJ-3414 Time Limit:1000 ms Memory Limit:65536 K Description You are given two po...
974 0
POJ 1012 Joseph
Joseph Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 53862   Accepted: 20551 Description The Joseph's problem is notoriously known.
820 0
poj 3620
题意:给出一个矩阵,其中有些格子干燥、有些潮湿。       如果一个潮湿的格子的相邻的四个方向有格子也是潮湿的,那么它们就可以构成更大       的湖泊,求最大的湖泊。       也就是求出最大的连在一块儿的潮湿的格子的数目。
556 0
POJ 2487 Stamps
Description Background Everybody hates Raymond. He’s the largest stamp collector on planet earth and because of that he always makes fun of all the others at the stamp collector parties.
1037 0