# 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/ ## 思路 背包问题  ## 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]; } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up