All pastes #239415 Raw Edit

Stuff

public text v1 · immutable
·published 2006-11-05 10:03 UTC
rendered paste body
#include <stdio.h>

int disp,changes;
int moves[1000];
int index = 0,found = 0;

void print()
{
	int i = 0;
	for(i = 0;i < index;i++)
		printf("%d\n",moves[i]);
}

int fun(int n,int value)
{
	if(found)
		return 1;
	if(n == changes && value == disp){
		found = 1;
		print();
		return 1;
	}
	if(n >= changes)
		return 0;
	moves[index++] = value;
	fun(n+1,value+1);
	fun(n+1,value-1);
	index--;
	return found;

}

int main()
{
	int n,i,val = 0;
	scanf("%d",&n);
	for(i = 0;i < n;i++)
	{
		scanf("%d %d",&changes,&disp);
		found = index = 0;
		val = fun(0,0);
		if(!val)
			printf("No");
		printf("\n");
	}
	return 0;
}