Cod sursa(job #1428815)

Utilizator alexandra_udristoiuUdristoiu Alexandra Maria alexandra_udristoiu Data 5 mai 2015 09:47:04
Problema Diamant Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.94 kb
#include<fstream>
#include<cstring>
#define DIM 401 * 401
using namespace std;
int n, m, i, j, a, x, k, s, b;
int v[DIM * 2], aux[DIM * 2];
ifstream fin("diamant.in");
ofstream fout("diamant.out");
int main(){
    fin>> n >> m >> x;
    v[DIM] = aux[DIM] = 1;
   for(i = 1; i <= n; i++){
        for(j = 1; j <= m; j++){
            s += i * j;
        }
   }
   b = DIM;
    for(i = 1; i <= n; i++){
        for(j = 1; j <= m; j++){
            a = i * j;
            for(k = DIM -s; k <= DIM + s; k++){
                if (k + a < 2 * DIM){
                    aux[k] = (v[k + a] + aux[k]) % 10000;
                }
                if (k - a >= 0){
                    aux[k] = (v[k - a] + aux[k]) % 10000;
                }
            }
             memcpy(v, aux, sizeof(aux));
        }
    }
    if(x >= -s && x <= s){
        fout<< v[x + DIM] <<"\n";
    }
    else{
        fout<<"0\n";
    }
    return 0;
}