The number of maximum subset
1000 ms | 内存限制: 65535
1
You are given a set with n distinct numbers of 1 to n, and your task is to calculate the number of maximum subsets with the following properties:
1:no two elements in the subset should be adjacent
2:it shouldn't be possible to add numbers to the subset without violating the first condition
For example, if n = 5, the number of maximum subsets which fulfill the above conditions is 4. The subsets are {1,3,5},{2,4},{2,5},{1,4}.
The input will consist of a sequence of numbers n,1 ≤ n ≤ 76. Each number will be on a separate line. The input will be terminated by EOF.
输出
Output the number of maximum subsets as described above on a single line. The number of all subsets will be less than 2^31.
样例输入
1
2
3
4
5
30
样例输出
1
2
2
3
4
4410
题意:给定一组n个不同的数字1到N,你的任务是计算具有以下属性的最大数目的子集:
1:没有两个元素应相邻子集。
2:不可以添加编号的子集在不违反第一条件。
例如,如果n = 5,最大的子集,满足上述条件的号码是4。的子集{ } { } 1,2,5,{ },{ 1,4 }。
规律题,方程:dp[i]=dp[i-2]+dp[i-3];
#include<cstdio>
int main()
{
int n, dp[80];
dp[0] = dp[1] = 1;
dp[2] = 2;
for(int i = 3; i <= 76; i++)
dp[i] = dp[i-2] + dp[i-3];
while(~scanf("%d", &n))
{
printf("%d\n", dp[n]);
}
return 0;
}