Cod sursa(job #1044691)

Utilizator narcis_vsGemene Narcis - Gabriel narcis_vs Data 30 noiembrie 2013 11:30:09
Problema Pavare2 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 2.62 kb
/*
#include <fstream>
#include <cstring>

using namespace std;
const int Base = 10;
const int Nmax = 105;
int N ,A ,B;

class Huge
{
    public: int V[100];
    Huge ()
    {
        memset(V, 0, sizeof(V));
    }
    Huge (int X)
    {
        *this = X;
    }

    Huge operator= (int X)
    {
        memset(V, 0, sizeof(V));
        for(; X; X /= Base)
            V[++V[0]] = X % Base;
        return *this;
    }
    Huge operator= (Huge X)
    {
        memcpy(V, X.V, sizeof(X.V));
        return *this;
    }

    Huge operator+ (Huge X) const
    {
        int i, T = 0;
        Huge Now;
        for(i = 1; i <= V[0] || i <= X.V[0] || T; i++, T /= Base)
            Now.V[i] = (T += V[i] + X.V[i]) % Base;
        Now.V[0] = i - 1;
        return Now;
    }
    Huge operator+ (int X) const
    {
        return *this + Huge(X);
    }

    Huge operator* (Huge X) const
    {
        Huge Now;
        int i, j;
        long long T = 0;
        for(i = 1; i <= V[0]; i ++)
        {
            for(j = 1, T = 0; j <= X.V[0] || T; j ++, T /= Base)
                Now.V[i + j - 1] = (T += 1LL * Now.V[i + j - 1] + 1LL * V[i] * X.V[j]) % Base;
            if(i + j - 2 >= Now.V[0]) Now.V[0] = i + j - 2;
        }
        return Now;
    }
    Huge operator* (int X) const
    {
        return *this * Huge(X);
    }

    void Print() const
    {
        for(int i = V[0]; i >= 1; i--) printf("%d", V[i]);
        printf("\n");
    }
    inline void ToHugeNumber(char *s)
    {
        V[0] = 0;
        for(int i = strlen(s)-1;i >= 0; --i)
            V[++V[0]] = s[i]-'0';
    }
    inline void sub(const Huge B)
    {
          int i, t = 0;
          for (i = 1; i <= V[0]; i++)
          {
                  V[i] -= ((i <= B.V[0]) ? B.V[i] : 0) + t;
                  V[i] += (t = V[i] < 0) * Base;
          }
          for (; V[0] > 1 && !V[V[0]]; V[0]--);
    }
};
Huge dp[Nmax][2][Nmax], a , sol;
int main()
{
    char s[Nmax];
    int i, j;
    ifstream f("pavare2.in");
    freopen("pavare.out","w",stdout);
    f >> N >> A >> B >> (s+1);
    f.close();
    a.ToHugeNumber(s+1);
    dp[N][0][1] = dp[N][0][1] = 1;
    for(i = N-1;i ;--i)
    {
        for(j = 2;j <= A; ++j)
            dp[i][0][j] = dp[i+1][0][j-1];
        for(j = 2;j <= B; ++j)
            dp[i][1][j] = dp[i+1][1][j-1];

        for(j = 1;j <= B; ++j)
            dp[i][0][1] = dp[i][0][1] + dp[i+1][1][j];
        for(j = 1;j <= A; ++j)
            dp[i][1][1] = dp[i][1][1] + dp[i+1][0][j];
    }
    sol = dp[1][0][1] + dp[1][1][1];
    sol.Print();
    return 0;
}

*/