放苹果(暴力)

放苹果
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 33214   Accepted: 20600

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
题解:直接暴力,刚开始还以为不能有盘子空着吶,允许有盘子空着,所以直接暴力就可以了:
代码:
package com.lanqiao.week2;

import java.util.Scanner;

public class H {
    private static Scanner cin;
    static{
        cin = new Scanner(System.in);
    }
    
    private static int k;
    static void cal(int M, int N, int cnt, int cur, int v){
        if(cnt < 0){
            
            return;
        }
        if(v == M){
            //    System.out.println("M = " + M + "N = " + N + "cnt = " + cnt + "cur = " + cur + "v = " + v);
            k++;
            return;    
        }
        if(cur > M || v > M){
            
            return;
        }
        for(int i = 0; i <= N; i++){
            
            cal(M, N, cnt - i, cur + 1, v + cur * i);
            
        }
    }
    public static void main(String[] args) {
        int t = cin.nextInt();
        int M, N;
        while(t-- > 0){
            M = cin.nextInt();
            N = cin.nextInt();
            k = 0;
            cal(M, N, N, 1, 0);
            System.out.println(k);
        }
    }
}
A - A
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
Submit Status

Description

给定三条边,请你判断一下能不能组成一个三角形。
 

Input

输入数据第一行包含一个数M,接下有M行,每行一个实例,包含三个正数A,B,C。其中A,B,C <1000;
 

Output

对于每个测试实例,如果三条边长A,B,C能组成三角形的话,输出YES,否则NO。
 

Sample Input

2 1 2 3 2 2 2
 

Sample Output

NO YES
原文地址:https://www.cnblogs.com/handsomecui/p/6556994.html