nyoj1138 The number of maximum subset 递推

来源:互联网 发布:apache禁止访问根目录 编辑:程序博客网 时间:2024/06/05 13:51

题目链接~传送门

题目大意:no two elements in the subset should be adjacent

                   it shouldn't be possible to add numbers to the subset without violating the first condition

                  求最大的子集的个数

解题思路:123456111 31 31 3 51 3 5 2222 42 42 4 6   1 42 51 3 6    1 42 5     1 4 6      

有对比可看出,f(n)是由f(n-2)和f(n-3) 递推过来的

所以可得代码

 #include<stdio.h>int main(){    int n;    int a[100];    a[1]=1;a[2]=2;a[3]=2;    for(int i=4;i<77;i++)        a[i]=a[i-3]+a[i-2];    while(scanf("%d",&n)!=EOF) printf("%d\n",a[n]);}        


0 0
原创粉丝点击