96. 奇怪的汉诺塔

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int d[15],f[15];
int main()
{
d[1]=1;
for(int i=2;i<=12;i++)
d[i]=d[i-1]*2+1;
memset(f,0x3f,sizeof(f));
f[1]=1;
for(int i=2;i<=12;i++)
{
for(int j=1;j<i;j++)
{
f[i]=min(f[i],f[j]*2+d[i-j]);
}
}
for (int i = 1; i <= 12; i ++ )
cout << f[i]<<endl;
return 0;
}
Donate
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2022-2024 CPY
  • Visitors: | Views:

请我喝杯咖啡吧~

支付宝
微信