放蘋果(暴力)

來源:互聯網
上載者:User

標籤:poi   ott   ext   turn   system   org   log   ges   判斷   

放蘋果
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

17 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 - ATime Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64uSubmit Status

Description

給定三條邊,請你判斷一下能不能組成一個三角形。 

Input

輸入資料第一行包含一個數M,接下有M行,每行一個執行個體,包含三個正數A,B,C。其中A,B,C <1000; 

Output

對於每個測試執行個體,如果三條邊長A,B,C能組成三角形的話,輸出YES,否則NO。 

Sample Input

21 2 32 2 2  

Sample Output

NOYES

放蘋果(暴力)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.