编程问题(有更多加分)

来源:百度知道 编辑:UC知道 时间:2024/06/14 07:45:36
Timelimit 3s;

Assume that you are making square matrices by putting pebbles in order to make each matrix symmetrically. For example,

OOOO
OO
O
O
is a symmetric matrix composed of 8 pebbles. We say a matrix is symmetric if and only if the matrix has no change if we flip it around its diagonal line from the upper-left corner to the lower-right corner and the number of pebbles in a line of the matrix is less or equal than the number of pebbles in its upper line. And following is another symmetric matrix composed of 8 pebbles:
OOO
OOO
OO
But following matrix is NOT a symmetric matrix, because the second line has 4 pebbles while the first line has only 2 pebbles.
OO
OOOO
O
O
In this problem, you are required to write a program to determine how many symmetric matrices there are composed of N pebbles, where 1<=N<=300.

Input Specification
The input consists of several lines, each of

#include<stdio.h>

#define N 250///254的时候,会溢出
int a[N]={0};//保存计算结果,加速程序运行

int func(int n)
{
int sum,i,m;

if(n==0 || n==1)
{
return 1;
}
else if(n==2)
{
return 0;
}
else if(a[n-1]!=0)
{
return a[n-1];
}
for(sum=0,i=(n+1)/2;i>0;i--)
{
m=(2*i-1);
if((n-m)>(i-1)*(i-1))
{
break;
}
sum+=func(n-m);
}
a[n-1]=sum;
return sum;
}

int main()
{
int n;

while(true)
{
scanf("%d",&n);
if(n>N||n<1)
{
break;
}
printf("%d\n",func(n));
}
return 0;
}

更多是多少啊?
看这个实在是花费时间啊!

翻译一下,也许我可以帮你。但是不翻译我根本就帮不了你。

大家讨论下啊,应该不简单哦。先看看我对题目的理解啊,不是专业学软件啊,希望有高手支招。
/*******************************************************************/
1. 输入1~300的整数,根据规则来输出一共最多有多少个“正方形”;