zoukankan      html  css  js  c++  java
  • 42.递归算法---数的划分


     

    2001NOIP全国联赛提高组

     时间限制: 1 s

     空间限制: 128000 KB

     题目等级 : 黄金 Gold

    题解

    题目描述 Description

    将整数n分成k份,且每份不能为空,任意两种划分方案不能相同(不考虑顺序)
    例如:n=7k=3,下面三种划分方案被认为是相同的。
    1 1 5

    1 5 1

    5 1 1
    问有多少种不同的分法。

    输入描述 Input Description

    输入:nk (62<=k<=6)

    输出描述 Output Description


    输出:一个整数,即不同的分法。

    样例输入 Sample Input

     7 3

    样例输出 Sample Output

    4

    数据范围及提示 Data Size & Hint

     {四种分法为:115;124;133;223;}

    代码:

    #include

    using namespace std;

    #include

    int f(int,int,int);

    int main()

    {

        int n,k;

           cin>>n>>k;

           cout<<f(n,k,1)<<endl;

           return 0;

    }

    int f(int a,int b,int c)

    {

           int g=0;

           if(b==1) return 1;

           else{

                  for(int i=c;i<=a/b;++i)//i<=a/b的含义就是当前的a/ba分为b分,每一份起码大于i曾能再用i去分a这个数,

                  g+=f(a-i,b-1,i);

                  return g;

           }

    }

  • 相关阅读:
    ActiveMQ的用途
    HTTP 状态码的完整列表
    Linux中脚本运行错误(坏的解释器:没有那个文件或目录)
    Linux下ping: unknown host www.baidu.com的解决办法
    python中的collection
    Table里嵌套ASPXGridView
    致2015
    WPF学习之Binding(二)
    WPF学习之Binding(一)
    WPF UI布局(Layout)
  • 原文地址:https://www.cnblogs.com/csgc0131123/p/5290427.html
Copyright © 2011-2022 走看看