Cod sursa(job #2726142)

Utilizator valentinchipuc123Valentin Chipuc valentinchipuc123 Data 20 martie 2021 14:00:52
Problema Diamant Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <iostream>
#include <fstream>

using namespace std;

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

int n,m,x;
int salt;
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 ){
  g<<'0'<<'\n';
  return 0;
 }

 g<<dp[salt+x];
}