题目: 点击打开链接
不会把题目弄过来,只好给个链接。。 这道题和我写的
Ignatius and the Princess III解法一样,只有一点改变,下面是代码:
using namespace std;
int a1[310], a2[310];
int main()
{
int n;
while (cin >> n)
{
if (n == 0)return 0;
for (int i = 0; i <= n; i++)
{
a1[i] = 1;
a2[i] = 0;
}
for (int t=2,i=4; i <= n; t++,i=(t*t))//求所有多项式的乘积
{
for (int j = 0; j <= n; j++)//求相邻两多项式乘积,注意数组下标为次数,数组值为系数,故a2下标每次加j,对应的值每次加a1[j]
{
for (int k = 0; k + j <= n; k += i)
{
a2[k + j] += a1[j];
}
}
for (int i = 0; i <= n; i++)//将本次结果作为a1
{
a1[i] = a2[i];
a2[i] = 0;
}
}
cout << a1[n] << endl;
}
}