CODEVS——T 2956 排队问题

http://codevs.cn/problem/2956/

 时间限制: 1 s
 空间限制: 32000 KB
 题目等级 : 黄金 Gold
 查看运行结果
 
 
题目描述  Description

有N个学生去食堂,可教官规定:必须2人或3人组成一组,求有多少种不同分组的方法。

 

输入描述  Input Description

一个数,N

输出描述  Output Description

一个数,即答案。

样例输入  Sample Input

6

样例输出  Sample Output

2

数据范围及提示  Data Size & Hint

N<=150

 

 1 #include <cstdio>
 2 
 3 int n,ans;
 4 
 5 void DFS(int sum)
 6 {
 7     if(sum>n) return ;
 8     if(sum==n) { ans++; return ; }
 9     if(sum+2<=n) DFS(sum+2);
10     if(sum+3<=n) DFS(sum+3);
11 }
12 
13 int Presist()
14 {
15     scanf("%d",&n);
16     DFS(0);
17     printf("%d\n",ans);
18     return 0;
19 }
20 
21 int Aptal=Presist();
22 int main(int argc,char*argv[]){;}
深搜50
 1 #include <cstdio>
 2 
 3 int n,ans;
 4 long long f[155];
 5 
 6 int Presist()
 7 {
 8     scanf("%d",&n);
 9     f[2]=f[3]=1;
10     for(int i=4; i<=n; ++i) f[i]=f[i-2]+f[i-3];
11     printf("%lld\n",f[n]);
12     return 0;
13 }
14 
15 int Aptal=Presist();
16 int main(int argc,char*argv[]){;}
递推AC

 

转载于:https://www.cnblogs.com/Shy-key/p/7593659.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值