Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- string b;
- cout << "Input B:\n";
- cin >> b;
- int n = b.size();
- vector<vector<int>> dp(n + 1, vector<int> (10, 1));
- for(int i = 1; i <= n; i++) {
- int bdigit = (b[i-1] - '0');
- for(int j = 0; j <= 9; j++) {
- dp[i][j] = 0;
- if(j - bdigit >= 0) { // a[i] - a[i-1] = b[i-1]
- dp[i][j] += dp[i-1][j-bdigit];
- }
- if(j + bdigit <= 9 && bdigit != 0) { // a[i] - a[i-1] = -b[i-1]
- dp[i][j] += dp[i-1][j+bdigit];
- }
- }
- }
- int Nb = 0;
- for(int i = 0; i <= 9; i++) {
- Nb += dp[n][i];
- }
- cout << Nb;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement