zoukankan      html  css  js  c++  java
  • POJ 1664 放苹果

    放苹果
    Time Limit: 1000MS   Memory Limit: 10000K
    Total Submissions: 23639   Accepted: 14999

    Description

    把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法?(用K表示)5,1,1和1,5,1 是同一种分法。

    Input

    第一行是测试数据的数目t(0 <= t <= 20)。以下每行均包含二个整数M和N,以空格分开。1<=M,N<=10。

    Output

    对输入的每组数据M和N,用一行输出相应的K。

    Sample Input

    1
    7 3
    

    Sample Output

    8
    #include <stdio.h>
    #include <iostream>
    using namespace std;
    
    int n;
    int ans;
    int result;
    
    void DFS(int index, int from, int sum)
    {
        if (index == n)
        {
            if (sum == result)
            {
                ans++;
            }
            return;
        }
        for (int i = from; i <= result; i++)
        {
            DFS(index + 1, i, sum + i);
        }
    }
    
    int main()
    {
        int nCase;
        scanf("%d", &nCase);
        for (int i = 0; i < nCase; i++)
        {
            scanf("%d%d", &result, &n);
            ans = 0;
            DFS(0, 0, 0);
            printf("%d
    ", ans);
        }
        return 0;
    }
  • 相关阅读:
    性能测试概念
    接口测试概念
    SQL多表查询
    手机App测试概念
    App测试页面滑动
    自动化测试概念
    Monkey 命令
    Tomcat+JDK安装和配置
    Linux系统FTP安装、安装和使用
    Web测试方法(一)
  • 原文地址:https://www.cnblogs.com/lzmfywz/p/3202103.html
Copyright © 2011-2022 走看看