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

Common Board

HEYYYY CAN ANYONE HELP!!!!!!!! HAS NOONE SOLVED "BOXES"?
Posted by Algorist 22 Dec 2001 01:24
My source :

#include <stdio.h>

#define UNDEFINED 0
#define MAXBOX 22
#define MAXR 16
#define MAXB 16

long double ways[MAXBOX][MAXR][MAXB];
int box,red,blue;
FILE *f;

void init(void) {
int i,j,k;
 f = stdin;
// f = fopen(fin,"r");
 fscanf(f,"%d %d %d",&box,&red,&blue);
// fclose(f);
 for (i=1;i<=box;i++)
  for (j=0;j<=red;j++)
   for (k=0;k<=red;k++)
    ways[i][j][k]=UNDEFINED;
 for (i=0;i<=red;i++)
  for (j=0;j<=blue;j++)
   ways[0][i][j]=1;
}

long double solve(int boxes,int r,int b) {
int i,j;
long double sum=0;
 if (ways[boxes][r][b]!=UNDEFINED) return ways[boxes][r][b];
 for (i=0;i<=r;i++)
  for (j=0;j<=b;j++) {
    sum+=solve(boxes-1,r-i,b-j);
   }
 ways[boxes][r][b]=sum;
 return ways[boxes][r][b];
}

int main(void) {
 init();
 f = stdout;
// f = fopen(fout,"w");
 solve(box,red,blue);
 fprintf(f,"%0.0Lf\n",ways[box][red][blue]);
 return 0;
}


It works on my PC on all tests. Does it on yours too?


AND ALSO - What compiler does timus use?
This problem is very easy.Why don't you ask me?(Email to:"hyz12345678@163.com")
Posted by Huang Yizheng 22 Dec 2001 08:44
> My source :
>
> #include <stdio.h>
>
> #define UNDEFINED 0
> #define MAXBOX 22
> #define MAXR 16
> #define MAXB 16
>
> long double ways[MAXBOX][MAXR][MAXB];
> int box,red,blue;
> FILE *f;
>
> void init(void) {
> int i,j,k;
>  f = stdin;
> // f = fopen(fin,"r");
>  fscanf(f,"%d %d %d",&box,&red,&blue);
> // fclose(f);
>  for (i=1;i<=box;i++)
>   for (j=0;j<=red;j++)
>    for (k=0;k<=red;k++)
>     ways[i][j][k]=UNDEFINED;
>  for (i=0;i<=red;i++)
>   for (j=0;j<=blue;j++)
>    ways[0][i][j]=1;
> }
>
> long double solve(int boxes,int r,int b) {
> int i,j;
> long double sum=0;
>  if (ways[boxes][r][b]!=UNDEFINED) return ways[boxes][r][b];
>  for (i=0;i<=r;i++)
>   for (j=0;j<=b;j++) {
>     sum+=solve(boxes-1,r-i,b-j);
>    }
>  ways[boxes][r][b]=sum;
>  return ways[boxes][r][b];
> }
>
> int main(void) {
>  init();
>  f = stdout;
> // f = fopen(fout,"w");
>  solve(box,red,blue);
>  fprintf(f,"%0.0Lf\n",ways[box][red][blue]);
>  return 0;
> }
>
>
> It works on my PC on all tests. Does it on yours too?
>
>
> AND ALSO - What compiler does timus use?
What's wrong with your email box?I sent letters to you for times,for I always got "Undelieved letter returned".
Posted by Huang Yizheng 23 Dec 2001 17:19
> My source :
>
> #include <stdio.h>
>
> #define UNDEFINED 0
> #define MAXBOX 22
> #define MAXR 16
> #define MAXB 16
>
> long double ways[MAXBOX][MAXR][MAXB];
> int box,red,blue;
> FILE *f;
>
> void init(void) {
> int i,j,k;
>  f = stdin;
> // f = fopen(fin,"r");
>  fscanf(f,"%d %d %d",&box,&red,&blue);
> // fclose(f);
>  for (i=1;i<=box;i++)
>   for (j=0;j<=red;j++)
>    for (k=0;k<=red;k++)
>     ways[i][j][k]=UNDEFINED;
>  for (i=0;i<=red;i++)
>   for (j=0;j<=blue;j++)
>    ways[0][i][j]=1;
> }
>
> long double solve(int boxes,int r,int b) {
> int i,j;
> long double sum=0;
>  if (ways[boxes][r][b]!=UNDEFINED) return ways[boxes][r][b];
>  for (i=0;i<=r;i++)
>   for (j=0;j<=b;j++) {
>     sum+=solve(boxes-1,r-i,b-j);
>    }
>  ways[boxes][r][b]=sum;
>  return ways[boxes][r][b];
> }
>
> int main(void) {
>  init();
>  f = stdout;
> // f = fopen(fout,"w");
>  solve(box,red,blue);
>  fprintf(f,"%0.0Lf\n",ways[box][red][blue]);
>  return 0;
> }
>
>
> It works on my PC on all tests. Does it on yours too?
>
>
> AND ALSO - What compiler does timus use?