#what is wrong with my code?

1 messages · Page 1 of 1 (latest)

fleet nebula
#

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

const long long mod = 1e9+7;

long long topdown(long long indice, long long target, vector<long long> &dp, vector<long long> &v)
{
if (target == 0)
return 1;

if (dp[indice] != -1)
    return dp[indice];

long long take = 0;

for (int i = 1; i <= target; i++){
    take = (take + topdown(indice, target - v[i], dp, v)) % mod;}

return dp[indice] = take;

}

long long initializare(vector<long long> &v, long long target, long long indice)
{
vector<long long> dp(indice + 1, -1);
return topdown(indice-1, target, dp, v);
}

int main()
{
long long indice, target;
cin >> indice >> target;
vector<long long> v(indice+1);

for (int i = 0; i < indice; i++)
    cin >> v[i];

cout << initializare(v, target, indice);

return 0;

}
i know its not optimized but i want this to work first. pls help nooo

bronze galeBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

distant jay
#

you may want to give some thought that the fact that 100,000,007 is prime may be significant in this problem

fleet nebula
#

hmm why