---
# System prepended metadata

title: 1155. Number of Dice Rolls With Target Sum
tags: [Leetcode, Bloomberg, Knapsack problem, Medium]

---

# 1155. Number of Dice Rolls With Target Sum
###### tags: `Leetcode` `Medium` `Bloomberg` `Knapsack problem`
Link: https://leetcode.com/problems/number-of-dice-rolls-with-target-sum/
## 思路 
背包问题
![](https://i.imgur.com/MYKyATa.png)
## Code
```java=
class Solution {
    public int numRollsToTarget(int d, int f, int target) {
        int[][] dp = new int[d+1][target+1];
        for(int i = 1;i <= d;i++){
            for(int j = 1;j <= target;j++){
                if(i==1 && j<=f) dp[i][j] = 1;
                for(int k = 1;k <= f;k++){
                    if(j-k>0 && dp[i-1][j-k]!=0) dp[i][j]=(dp[i][j]+dp[i-1][j-k])%1000000007;
                }
            }
        }
        return dp[d][target];
    }
    
}
```