Advertisement
Farjana_akter

Untitled

Sep 2nd, 2020
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long int ll;
  4.  
  5.  
  6. ll m,n,arr[100],dp[57][67];
  7.  
  8. ll dgdp(ll pos,ll pre)
  9. {
  10. if(pos==n)
  11. {
  12. return 1;
  13. }
  14. if(dp[pos][pre]!=-1)
  15. return dp[pos][pre];
  16. ll ans=0;
  17. for(ll i=0;i<m;i++)
  18. {
  19. if(abs(arr[i]-pre)<=2 || pre==0)
  20. ans+=dgdp(pos+1,arr[i]);
  21. }
  22. return dp[pos][pre]=ans;
  23. }
  24.  
  25. int main()
  26. {
  27. // freopen("input.txt","r",stdin);
  28. // freopen("output.txt","w",stdout);
  29.  
  30. ll i,j,k, t,cas;
  31. cin>>t;
  32. for(cas=1;cas<=t;cas++)
  33. {
  34. cin>>m>>n;
  35. for(i=0;i<m;i++)
  36. {
  37. cin>>arr[i];
  38. }
  39. memset(dp,-1,sizeof(dp));
  40. cout<<"Case "<<cas<<": "<<dgdp(0,0)<<endl;
  41. }
  42. return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement