Cod sursa(job #1775655)

Utilizator stefantagaTaga Stefan stefantaga Data 10 octombrie 2016 16:48:47
Problema Diamant Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <fstream>

using namespace std;
ifstream f("diamant.in");
ofstream g("diamant.out");
long long d[2000][2000],gg,w[1005],n,m,k,yx;
int main()
{
    int i,j;
    f>>n>>m>>gg;
    if (gg<0)gg=gg*(-1);
    if (gg>44100)
    {
        g<<"0";
        return 0;
    }
    for (i=1;i<=n;i++)
    {
        for (j=1;j<=m;j++)
        {
            w[++k]=i*j;
        }
    }
    d[0][0]=1;
    yx=gg;
    for (i=1;i<=k;i++)
    {
        for (j=0;j<=yx;j++)
        {
            if (w[i]<=j)
            {
                d[i][j]=max(d[i-1][j],d[i-1][j-w[i]]+1);
            }
            else
            {
                d[i][j]=d[i-1][j];
            }
        }
    }
    g<<d[k][yx]%10000;
    return 0;
}