ACM -- 算法小结(九)DP之Humble numbers

时间:2024-05-27 09:35:26

     DP -- Humble numbers 

//一开始理解错题意了,题意是是说一些只有唯一一个质因数(质因数只包括2,3,5,7)组成的数组,请找出第n个数是多少
//无疑,先打表,否则果断超时 #include <iostream>
using namespace std;
int a[];
int b[] = {, , , };
int ans[];
int main()
{
int i,j;
for(i = ; i < ; i++)
a[i] = ;
ans[] = ;
for(i = ; i < ; i++)
{
int tmp = ;
for(j = ; j < ; j++)
{
if(ans[a[j]] * b[j] < ans[a[tmp]] * b[tmp])
tmp = j;
}
ans[i] = ans[a[tmp]] * b[tmp];
for(j = ; j < ; j++)
{
if(ans[i] == ans[a[j]] * b[j])
a[j]++;
}
} int n;
while(cin >> n && n != )
{
cout << "The " << n;
if(n % == && n % != )
cout << "st";
else
if(n % == && n % != )
cout << "nd";
else
if(n % == && n % != )
cout << "rd";
else
cout << "th";
cout << " humble number is ";
cout << ans[n - ] << ".\n";
}
return ;
}