Cod sursa(job #2032640)

Utilizator AlexandruLuchianov1Alex Luchianov AlexandruLuchianov1 Data 5 octombrie 2017 15:14:35
Problema Diamant Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.83 kb
#include <iostream>
#include <fstream>

using namespace std;
ifstream in ("diamant.in");
ofstream out ("diamant.out");
int const nmax = 20;
int const valmax = nmax * nmax;
int const totalsum = valmax * valmax;
int dp[5 + valmax + totalsum * 2];
int dp2[5 + valmax + totalsum * 2];
#define dp (dp + totalsum)
#define dp2 (dp2 + totalsum)

int main()
{
  int n , m , x;
  in>>n>>m>>x;
  dp[0] = 1;
  for(int i = 1 ; i <= n ;i++){
    for(int j = 1 ; j <= m ;j++){
      int sum = i * j;
      for(int t = -totalsum ;t <= totalsum ;t++){
        dp2[t] += dp[t];
        if(0 < dp[t]){
          dp2[t - sum] += dp[t];
          dp2[t + sum] += dp[t];
        }
      }
      for(int t = -totalsum ;t <= totalsum ;t++){
        dp[t] = dp2[t];
        dp2[t] = 0;
      }
    }
  }
  out<<dp[x];
  return 0;
}