SuitNdtie

Call DP

Apr 13th, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include<stdio.h>
  2. int n;
  3. int space[10] = {2,3,4,3,4,5,4,3,5,3};
  4. int adj[10][5] = {{0,8},{1,2,4},{1,2,3,5},{2,3,6},{1,4,5,7},{2,4,5,6,8},{3,5,6,9},{4,7,8},{0,5,7,8,9},{6,8,9}};
  5. int dp[10][16];
  6. int call(int num,int pos)
  7. {
  8.     if(pos >= n)return 1;
  9.     if(dp[num][pos])return dp[num][pos];
  10.     int sum = 0;
  11.     for(int i=0;i<space[num];i++){
  12.         sum += call(adj[num][i],pos+1);
  13.     }
  14.     return dp[num][pos] = sum;
  15. }
  16. int main()
  17. {
  18.     scanf("%d",&n);
  19.     int ans = 0;
  20.     for(int i=0;i<=9;i++){
  21.         ans += call(i,1);
  22.     }
  23.     printf("%d",ans);
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment