Your task is to count the number of ways to construct sum by throwing a dice one or more times. Each throw produces an outcome between and .
For example, if , there are ways:
Input
The only input line has an integer .
Output
Print the number of ways modulo .
Constraints
Example
Input:3
Output:4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
int main() { | |
int mod = 1e9+7; | |
int n, target; | |
cin >> n >> target; | |
vector<int> x(n); | |
for (int&v : x) cin >> v; | |
vector<vector<int>> dp(n+1,vector<int>(target+1,0)); | |
dp[0][0] = 1; | |
for (int i = 1; i <= n; i++) { | |
for (int j = 0; j <= target; j++) { | |
dp[i][j] = dp[i-1][j]; | |
int left = j-x[i-1]; | |
if (left >= 0) { | |
(dp[i][j] += dp[i][left]) %= mod; | |
} | |
} | |
} | |
cout << dp[n][target] << endl; | |
} |
No comments:
Post a Comment