humble number hdu 1058

刚开始想暴力,想来想去还是照谢大说的DP吧

不过这输出有点蛋疼

代码:

#include 
#include 
#include 
using namespace std;
long long num[6000];
long long min(long long a,long long b,long long c,long long d)
{
    long long k;
    if(a>b)
    k=b;
    else
    k=a;
    if(k>c)
    k=c;
    if(k>d)
    k=d;
    return k;
}
int main()
{
    num[0]=1;
    long long len,n,i,j,k,m,ok;
    i=j=k=m=0;
    for(n=1;n<6005;n++)
    {
        ok=1;
        num[n]=min(num[i]*2,num[j]*3,num[k]*5,num[m]*7);
        if(num[n]==num[i]*2)
        i++;
        if(num[n]==num[j]*3)
        j++;
        if(num[n]==num[k]*5)
        k++;
        if(num[n]==num[m]*7)
        m++;
    }
    while(scanf("%I64d",&len),len)
    {
    if(len%100>=11&&len%100<=20)
    {
        printf("The %I64dth humble number is %I64d.\n",len,num[len-1]);
        continue;
    }
    if(len%10==1)
    printf("The %I64dst humble number is %I64d.\n",len,num[len-1]);
    else if(len%10==2)
    printf("The %I64dnd humble number is %I64d.\n",len,num[len-1]);
    else if(len%10==3)
    printf("The %I64drd humble number is %I64d.\n",len,num[len-1]);
    else
    printf("The %I64dth humble number is %I64d.\n",len,num[len-1]);
    }
}



你可能感兴趣的:(动态规划,hdu)