Reach a given score

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];
    }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值