关于D题,我不理解???? 正常求解是对的,但是我先预处理出来所有情况,查表做,结果居然wa了,求大神解答
#include <cmath>
using namespace std;
typedef long long LL;
int n;
int l, r;
int step;
LL f[666];
int g[99][99];
void dfs(int u, LL s)
{
if(u > 7) return ;
if(s == r)
{
step = min(step, u);
return ;
}
if(s <= 15 && f[s]) dfs(u + 1, f[s]);
dfs(u + 1, LL(sqrt(s)));
dfs(u + 1, LL(ceil(sqrt(s))));
}
int main()
{
f[0] = 1;
for(int i = 1; i <= 15; i ++ ) f[i] = f[i - 1] * i;
f[0] = 0;
cin >> n;
for(int i = 1; i <= 7; i ++ )
for(int j = i; j <= 7; j ++ )
{
r = j;
step = 99;
dfs(0, i);
if(step == 99) step = -1;
g[i][j] = step;
}
while(n -- )
{
cin >> l >> r;
// cout << g[l][r] << endl; //预处理出所有情况, 结果这个wa掉了???
//下面是正常求解, 这个居然对了??
step = 99;
dfs(0, l);
if(step == 99) step = -1;
cout << step << endl;
}
return 0;
}