Per svolgere lotteria ho provato ad implementare una semplice funzione che ricorsive che trova tutte le possibili combinazioni usando la memoizzazzione, ci sono comunque 2 casi che danno un output sbagliati ma non riesco a capire perché? C’è qualche errore?
#include<fstream>
#include<math.h>
using namespace std;
int n , m, mem[400000][20], jmax[20];
int f(int i, int k)
{
if(k==n) return 1;
int somma=0;
if(mem[i][k]!=0)
return mem[i][k];
else
for(int j=i*2;j<=jmax[k];j++)
{
int ris=f(j, k+1);
ris%=1000000007;
somma+=ris;
somma%= 1000000007;
}
mem[i][k]=somma;
return somma;
}
int main()
{
ifstream in("input.txt");
ofstream out("output.txt");
in>>n>>m;
jmax[n-1]=m;
for(int i=n-2;i>=0;i--) jmax[i]=jmax[i+1]/2;
int somma=0;
for(int i=1;i<m;i++)
{
int ris=f(i, 1);
ris%= 1000000007;
somma+=ris;
somma%= 1000000007;
}
out<<somma;
}