Cod sursa(job #1001638)

Utilizator DorelBarbuBarbu Dorel DorelBarbu Data 25 septembrie 2013 18:37:12
Problema Diamant Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.98 kb
#include <iostream>
#include <fstream>
#include <cstring>
#define decal 50000
#define MAX 300000
#define MOD 10000
using namespace std;

ifstream in("diamant.in");
ofstream out("diamant.out");

int n , m , x , a[MAX] , c[MAX] ;

int main()
{
    in>>n>>m>>x;

    int i , j , s_max = 0 , k ;

    a[decal] = 1 ;



    for( i = 1 ; i <= n ; i++ )
    {
        for( j = 1 ; j <= m ; j++ )
        {
            s_max += i*j ;
        }
    }

    if( x <= s_max )
    {
        for( i = 1 ; i <= n ; i++ )
        {
            for( j = 1 ; j <= m ; j++ )
            {
                for( k = -s_max ; k <= s_max ; k++ )
                {
                    c[k+decal] = a[k+decal] + a[k-i*j +decal] + a[k+i*j+decal] ;

                    c[k+decal] %= MOD ;
                }

                memcpy( a , c , sizeof(c) ) ;
            }

        }

        out<<a[x+decal];
    }
    else
    {
        out<<0 ;
    }

    return 0 ;

}