fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int dp[401][401][401];
  4. int solve(int z , int o , int l , int lz ,int lo ,int i)
  5. {
  6. if(z==0 && o==0)
  7. {
  8. return 1;
  9. }
  10.  
  11. if(dp[lz][lo][i] != -1)
  12. return dp[lz][lo][i];
  13. int ans = 0;
  14. if(z>0 && i-lo+1 <= l)
  15. {
  16. ans = solve(z-1 , o , l , i , lo , i+1);
  17. }
  18. if(o>0 && i-lz+1 <= l)
  19. {
  20. ans+= solve(z , o-1 , l , lz , i , i+1);
  21. }
  22.  
  23. return dp[lz][lo][i] = ans;
  24. }
  25. int numberOfStableArrays(int z, int o, int l) {
  26. memset(dp , -1 , sizeof(dp));
  27. return solve(z , o , l+1 , 0 , 0 , 0 );
  28. }
  29. int main() {
  30. cout<<numberOfStableArrays(3,3,2);
  31. return 0;
  32. }
Success #stdin #stdout 0.04s 255448KB
stdin
Standard input is empty
stdout
8