UVA 1647(p345)----Computer Transformations

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int O[1010][100];
int Z[1010][100];
void prepare()
{
    memset(O,0,sizeof(O));
    memset(Z,0,sizeof(Z));
    O[0][0]=O[1][0]=1;
    for(int i=2; i<1001; i++)
        for(int k=0; k<100; k++)
        {
            O[i][k]+=O[i-1][k]*2;
            Z[i][k]+=O[i-2][k]+Z[i-2][k];
            O[i][k+1]+=O[i][k]/10000;
            O[i][k]%=10000;
            Z[i][k+1]+=Z[i][k]/10000;
            Z[i][k]%=10000;
        }
}
int main()
{
    int n;
    prepare();
    while(scanf("%d",&n)==1&&n)
    {
        int l=99;
        while(l>0&&!Z[n][l]) l--;
        printf("%d",Z[n][l--]);
        while(l>=0)
            printf("%04d",Z[n][l--]);
        printf("\n");
    }
    return 0;
}

你可能感兴趣的:(UVA 1647(p345)----Computer Transformations)