Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define int int64_t
- #define F first
- #define S second
- using namespace std;
- const int N = 1e5+5;
- const int INF = 1e18+7;
- const int MOD = 1e9+7;
- map<pair<int,int>,int> dp;
- int n,k;
- int rec(int pos, int sum=0)
- {
- if(dp[{pos,sum}]!=-1) return dp[{pos,sum}];
- int t=0;
- if(sum==n) t++;
- if(pos==k){
- return dp[{pos,sum}]=t;
- }
- for(int i=0;i<=9;i++) t+=rec(pos+1,sum+i);
- if(pos!=0){
- for(int i=0;i<=9;i++) t+=rec(pos+1,sum-i);
- }
- return dp[{pos,sum}]=t;
- }
- int32_t main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0); cout.tie(0);
- // freopen("input.txt","r",stdin);
- // freopen("output.txt","w",stdout);
- for(int i=0;i<10;i++){
- for(int j=-100;j<100;j++){
- dp[{i,j}]=-1;
- }
- }
- cin>>n>>k;
- int ans = rec(0,0);
- if(n==0) ans--;
- cout<<ans<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement