Pagini recente » Cod sursa (job #680511) | Cod sursa (job #629123) | Cod sursa (job #2041322) | Cod sursa (job #599384) | Cod sursa (job #2591907)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("diamant.in");
ofstream fout("diamant.out");
const int NMAX = 20;
const int NORM = NMAX * NMAX * (NMAX + 1) * (NMAX + 1) / 4;
const int MOD = 1e4;
int dp[2][NORM * 2 + 5];
int main() {
int n, m, x;
fin>>n>>m>>x;
dp[1 & 1][-1 + NORM] = dp[1 & 1][NORM] = dp[1 & 1][1 + NORM] = 1;
int total = 1;
for( int i = 1; i <= n; i ++ ) {
for( int j = 1 + (i == 1); j <= m; j ++ ) {
int poz = (i - 1) * m + j;
total += i * j;
for( int cost = NORM - total; cost <= NORM + total; cost ++ )
dp[poz & 1][cost] = 0;
for( int k = -1; k <= 1; k ++ ) {
int newcost = k * (i * j);
for( int cost = NORM - total; cost <= NORM + total; cost ++ ) {
if( cost - newcost >= 0 && cost - newcost <= 2 * NORM )
dp[poz & 1][cost] = (dp[poz & 1][cost] + dp[(poz - 1) & 1][cost - newcost]) % MOD;
}
}
}
}
if( abs(x) > n * (n + 1) * m * (m + 1) / 4 )
fout<<"0";
else
fout<<dp[(n * m) & 1][x + NORM];
return 0;
}