Cod sursa(job #2726169)

Utilizator valentinchipuc123Valentin Chipuc valentinchipuc123 Data 20 martie 2021 14:11:26
Problema Diamant Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <iostream>
#include <fstream>

using namespace std;

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

int n,m;
int salt,x;
const int mod=10000;

int dp[100005],aux[100005];

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

 salt=0;

 for(int i=1;i<=n;i++)
  for(int j=1;j<=m;j++)
   salt+=i*j;

 dp[salt]=1;

 for(int i=1;i<=n;i++)
  for(int j=1;j<=m;j++){

   for(int z=0;z<=2*salt;z++) aux[z]=dp[z];

   for(int z=2*salt;z>=i*j;z--) aux[z]=(aux[z]+dp[z-i*j])%mod;
   for(int z=0;z<=salt*2-i*j;z++) aux[z]=(aux[z]+dp[z+i*j])%mod;

   for(int z=0;z<=salt*2;z++) dp[z]=aux[z];
 }

 if( x<-salt||salt<x ){
  g<<'0'<<'\n';
  return 0;
 }

 g<<dp[salt+x];
}