標籤: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
放蘋果(暴力)