半数集问题2

# include "stdio.h"
# include  "stdlib.h"
# include  "iostream.h"
# include  "malloc.h"
# include  "string.h"
// # include "mem.h"

 

 

//半数集问题


  long comp(int n);
/*

//(1) 一般算法,但低效


void  main()
 {
  int n;
  printf("------------");
  printf("\n半数集问题\n");
  printf("------------\n");
  printf("输入一自然数");
     scanf("%d",&n);
   printf("\n半数集个数为%d\n",comp(n));
 }

  long comp (int n)
  {
   long ans=1;
   if(n>1)
    for (int i=1;i<=n/2;i++)
   ans+=comp(i);
    return (ans);
  }

posted on 2009-05-08 15:45  whuzx  阅读(86)  评论(0编辑  收藏  举报

导航