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

    放苹果
    Time Limit: 1000MS   Memory Limit: 10000K
    Total Submissions: 25550   Accepted: 16249

    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



    Code:

    <pre name="code" class="java">import java.util.Scanner;
    
    public class Main {
        
        public static int Test(int m, int n) {
            if (m == 0 || n == 1) {
                return 1; 
            }
            if (n > m) {
                return Test(m, m);
            } else {
                return Test(m, n - 1) + Test(m - n, n);
            }
        }
    
        public static void main(String[] args) {
            Scanner cin = new Scanner(System.in);
            int i = cin.nextInt();
            for (int j = 0; j < i; j++) {
                int m = cin.nextInt();
                int n = cin.nextInt();
                System.out.println(Test(m, n));
            }
            cin.close();
        }
    }
    


    
    

  • 相关阅读:
    vue父子组件传值的方式
    定时任务写法
    仅仅为笔记
    consul剔除某个服务
    mybatis批量查询
    一次eureka的事故
    feign的工作原理
    JVM优化
    threadlocal应用
    秋招总结
  • 原文地址:https://www.cnblogs.com/gcczhongduan/p/4064652.html
Copyright © 2011-2022 走看看