zoukankan      html  css  js  c++  java
  • 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
    ",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
    ",f[n]);
    12     return 0;
    13 }
    14 
    15 int Aptal=Presist();
    16 int main(int argc,char*argv[]){;}
    递推AC
    ——每当你想要放弃的时候,就想想是为了什么才一路坚持到现在。
  • 相关阅读:
    Redis
    元类 metaclass
    聊一聊 Django 中间件
    Django rest framework
    聊一聊python的单例模式
    Django-admin管理工具
    MongoDB
    Beautifulsoup
    三、模型(一)
    九、Python发送QQ邮件(SMTP)
  • 原文地址:https://www.cnblogs.com/Shy-key/p/7593659.html
Copyright © 2011-2022 走看看