1D_DP_template

    0

    0

    abhinavmaurya747

    The memset() function will initialize all of the memory within the t array to -1.

    int t[constraint];
    Solution(){
      memset(t,-1,sizeof(t));
    }
    int solve(int n){
      if(n==0)
        return 1;
      if(n<0) return 0;
      if(t[n]!=-1)    return t[n];
      return t[n] = solve(n-1) + solve(n-2);
    }
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.