题目链接:http://acm.fzu.edu.cn/problem.php?pid=2205
题 意:给你 n个点,任意两个点由不超过一条边直接相连,而且没有点的边连向自身且不能有任意三个点能够相互连通,而且所有的边数目最多,
思 路:找规律
当n = 1, ans = 0; n = 2, ans = 1; n = 3, ans = 2; n = 4, ans = 4;n = 5, ans = 6;.....
可见:
a[2]-a[1] = 1;
a[3]-a[2] = 1;
a[4]-a[3] = 2;
a[5]-a[4] = 2;
a[6]-a[5] = 3;
a[7]-a[6] = 3;
。 。
。 。
。 。
显而易见.
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
typedef __int64 LL;
int ans[1003];
int main()
{
int T;
ans[0] = 0;
ans[1] = 0;
ans[2] = 1;
ans[3] = 2;
ans[4] = 4;
for( int i = 5; i < 1002; i ++ )
{
ans[i] = ans[i-1] + ans[i-2];
cout<<i<<" "<<ans[i]<<endl;
}
scanf ( "%d", &T );
while( T-- )
{
int n;
scanf( "%d", &n );
printf( "%d\n", ans[n] );
}
return 0;
}