Pagini recente » Cod sursa (job #2603933) | Cod sursa (job #3238105) | Cod sursa (job #2126798) | Cod sursa (job #1328723) | Cod sursa (job #7088)
Cod sursa(job #7088)
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define fin "1-sir.in"
#define fout "1-sir.out"
#define Nmax 257
int n,s,sol;
FILE *in,*out;
void go(int p,int sum,int el) {
int i,tmp;
//printf("%i ",el);
if (p==n+1) { if (sum==s) sol++; }
else
if (p==1)
for (i=0;i<=0;++i) {
go(p+1,i,i);
}
else {
if (rand()%2) {
tmp=el+1;
go(p+1,sum+tmp,tmp);
tmp=el-1;
go(p+1,sum+tmp,tmp);
}
else {
tmp=el-1;
go(p+1,sum+tmp,tmp);
tmp=el+1;
go(p+1,sum+tmp,tmp);
}
}
}
int main() {
in=fopen(fin,"r"); out=fopen(fout,"w");
fscanf(in,"%i%i",&n,&s);
srand(time(0));
go(1,0,0);
fprintf(out,"%i\n",sol);
fclose(in); fclose(out);
return 0;
}