Consider a game where a player can score 3 or 5 or 10 points in a move. Given a total score n, find number of distinct combinations to reach the given score.
Input:
The first line of input contains an integer T denoting the number of test cases.
The first line of each test case is N.
Output:
Print number of ways/combinations to reach the given score.
Constraints:
1 ≤ T ≤ 100
1 ≤ N ≤ 1000
Example:
Input
3
8
20
13
Output
1
4
2
Explanation
For 1st example when n = 8
{ 3, 5 } and {5, 3} are the two possible permutations but these represent the same cobmination. Hence output is 1.
**For More Examples Use Expected Output**
这道题的重点也是求组合,不能有重复。感觉目前还是不能够解释的很明白。
代码:
public static void main (String[] args)
{
//code
Scanner input = new Scanner(System.in);
int number = input.nextInt();
int[] inputArray = new int[number];
int[] result = new int[number];
for(int i=0;i<number;i++){
inputArray[i] = input.nextInt();
result[i] = compute(inputArray[i]);
}
for(int i=0;i<result.length;i++){
System.out.println(result[i]);
}
}
public static int compute(int n){
if(n <=0) return 0;
int[] dp = new int[n+1];
dp[0] = 1;
int[] scores = {3, 5, 10};
for(int i=0;i<scores.length;i++){
for(int j=1;j<=n;j++){
if(j-scores[i]>=0){
dp[j] += dp[j-scores[i]];
}
}
}
return dp[n];
}