ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1017. Staircases

My first code:

#include <stdio.h>
int n;
long long f[501][501], g[501][501], res;
void xxx(void)
{
     for (int i=0; i<=n; i++) f[0][i] = 1;
     for (int i=1; i<35 && i<=n; i++) {
         for (int j=0; j<=n; j++)
             for (int k=0; k<=n; k++) {
                 g[j][k] = f[j][k]; f[j][k] = 0;
             }
         for (int j=1; j<=n; j++) {
             for (int k=1; k<=j; k++) f[j][k] = f[j][k - 1] + g[j - k][k - 1];
             for (int k=j+1; k<=n; k++) f[j][k] = f[j][j];
         }
         res += f[n][n];
     }
}
int main(void)
{
    scanf("%d", &n);
    xxx();
    printf("%lld\n", --res);
    return 0;
}
WA for #6.

My second code:

#include <stdio.h>
int n;
__int64 f[501][501], g[501][501], res;
void xxx(void)
{
     for (int i=0; i<=n; i++) f[0][i] = 1;
     for (int i=1; i<35 && i<=n; i++) {
         for (int j=0; j<=n; j++)
             for (int k=0; k<=n; k++) {
                 g[j][k] = f[j][k]; f[j][k] = 0;
             }
         for (int j=1; j<=n; j++) {
             for (int k=1; k<=j; k++) f[j][k] = f[j][k - 1] + g[j - k][k - 1];
             for (int k=j+1; k<=n; k++) f[j][k] = f[j][j];
         }
         res += f[n][n];
     }
}
int main(void)
{
    scanf("%d", &n);
    xxx();
    printf("%I64d\n", --res);
    return 0;
}
AC.


Edited by author 30.08.2010 08:37
daftcoder [Yaroslavl SU] Re: Is there any difference between long long and __int64? // Problem 1017. Staircases 31 Aug 2010 01:32
Difference only here:
printf("%lld\n", --res);
printf("%I64d\n", --res);



#include <stdio.h>
int n;
long long f[501][501], g[501][501], res;
void xxx(void)
{
for (int i=0; i<=n; i++) f[0][i] = 1;
for (int i=1; i<35 && i<=n; i++) {
for (int j=0; j<=n; j++)
for (int k=0; k<=n; k++) {
g[j][k] = f[j][k]; f[j][k] = 0;
}
for (int j=1; j<=n; j++) {
for (int k=1; k<=j; k++) f[j][k] = f[j][k - 1] + g[j - k][k - 1];
for (int k=j+1; k<=n; k++) f[j][k] = f[j][j];
}
res += f[n][n];
}
}
int main(void)
{
scanf("%d", &n);
xxx();
printf("%I64d\n", --res);
return 0;
}

This is AC.