Help me in solving this problem

#include<bits/stdc++.h>
using namespace std;

bool cansum(vector<int>& num,vector<int>& dp,int x)
{
    if(x==0)
        return true;
    if(x<0)
        return false;
    if(dp[x])
        return dp[x];

    for(int i=0;i<num.size();i++)
    {
        if(cansum(num,dp,x-num[i]))
        {
            dp[x]=1;
            return true;
        }
    }
    dp[x]=0;
    return false;
}
int main()
{    int x=300;
     vector<int> num{7,14};

     vector<int> dp(x+1,0);
     cout<<cansum(num,dp,x);
     return 0;
}

why is this TLE?

@vebcodes
plzz send the problem link.

@dpcoder_007 this is a random cpp problem , we are given a vector of integers and an target , we can use each element of the vector infinite times , we have to tell if the given target can be generated by adding the elements in the vector , for example {2,3} and 7 should return true whereas {5,3} and 7 should return false

@vebcodes
its a problem of 2D dp not 1D first dimension will be i the index of the vector and second dimension will be target .