Why is it giving TLE?

Revision en2, by altreodo, 2022-06-01 05:31:36

Check this problem of CSES Coin Combination II

I have used memoization but still it is giving me TLE , I know CSES is tight in checking runtime but i have seen this type of solution in internet also but it is easily accepting but in mine it is showing TLE

CAN ANYBODY HELP ME?

#include <bits/stdc++.h>
 
using namespace std;
#define ll long long 
    ll MOD=1e9+7;
vector<vector<ll>>dp;
ll getter(vector<ll>&v,ll n,ll k){
    if(k==0){
        return (1);
    }
    if( k<0 || n>=v.size()){
        return 0;
    }
    if(dp[n][k-1]!=-1)return dp[n][k-1];
    return dp[n][k-1]=(getter(v,n+1,k)%MOD+getter(v,n,k-v[n])%MOD)%MOD;
}
int main() {
    ll n,k;
    cin>>n>>k;
    vector<ll>v(n);
    for(ll y=0;y<n;y++){
        cin>>v[y];
    }
    dp.resize(n+1,vector<ll>(k,-1));
    cout<<getter(v,0,k);
}
Tags dynamic programming, cses, coding

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English altreodo 2022-06-01 05:31:36 577
en1 English altreodo 2022-06-01 05:30:29 354 Initial revision (published)