Pagini recente » Cod sursa (job #87777) | Cod sursa (job #250975) | Cod sursa (job #214398) | Cod sursa (job #79273) | Cod sursa (job #923208)
Cod sursa(job #923208)
#include<fstream>
using namespace std;
ifstream fin("diamant.in");
ofstream fout("diamant.out");
const int R = 10000;
const int N = 44110;
int n, m, val[401], x, *d, *pl, *mn, l;
int auxd[2*N+1], auxpl[2*N+1], auxmn[2*N+1];
void initial(int a[N], int st, int dr){
for(int i=st; i<=dr; ++i)
a[i] = 0;
}
void afisare(int a[N], int st, int dr){
for(int i=st; i<=dr; ++i)
fout << a[i] << "\t";
fout << "\n";
}
int main(){
int i, j, k, c, st, dr;
d = auxd + N;
pl = auxpl + N;
mn = auxmn + N;
fin >> n >> m >> x;
d[0] = 1;
st = dr = 0;
if(-N<x && x<N){
for(i=1; i<=n; ++i)
for(k=1; k<=m; ++k){
c = i*k;
//PUN +C
for(j=dr; j>=st; j--)
{
pl[j+c] += d[j];
if(pl[j+c]>=R)
pl[j+c] -= R;
}
dr+= c;
//pun -c
for(j=st; j<=dr; j++)
{
mn[j-c] += d[j];
if(mn[j-c] >= R)
mn[j-c] -= R;
}
st-= c;
for(j=st; j<=dr; ++j)
{
d[j]+= pl[j] + mn[j];
if(d[j] >= R)
d[j]-= R;
}
initial(pl,st,dr);
initial(mn,st,dr);
//fout << "dupa adaugarea lui " << c << ":\t";
//afisare(d, -10, 10);
}
fout << d[x];
}
fin.close();
fout.close();
return 0;
}