Advertisement
nikunjsoni

1155

Jun 12th, 2021
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     int numRollsToTarget(int d, int f, int target) {
  4.         int mod = int(1e9)+7;
  5.         vector<int> ways(target+1, 0);
  6.         ways[0] = 1;
  7.         for(int rep = 1; rep <= d; ++rep){
  8.             vector<int> new_ways(target+1);
  9.             for(int sum = 0; sum <= target; sum++) {
  10.                 for(int face = 1; face <= f; face++) {
  11.                     if(sum-face >= 0) {
  12.                         new_ways[sum] += ways[sum-face];
  13.                         new_ways[sum] %= mod;
  14.                     }
  15.                 }
  16.             }
  17.             ways = new_ways;
  18.         }
  19.         return ways[target];
  20.     }
  21. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement