the code is running perfectly on my box...
i am using dev c++.
there is no stack overflow problem..
On May 17, 8:09 am, Ray [EMAIL PROTECTED] wrote:
Hi mirchi,
Do you test N = 16, H = 8?
It gives stack overflow when I run your program on my box.
I wrote a small one. May it help you.
#include stdio.h
#include stdlib.h
#include memory.h
const int MAX_N = 20;
void Solve (char a[], int n, int d, int rest)
{
if (d == n)
{
if (rest == 0)
{
a[n] = '\0';
printf (%s\n, a);
}
return;
}
if (n = rest + d)
{
if (n rest + d)
{
a[d] = '0';
Solve (a, n, d + 1, rest);
}
a[d] = '1';
Solve (a, n, d + 1, rest - 1);
}
}
void main ()
{
//freopen( out.txt, w, stdout);
char a[MAX_N] = {'\0'};
int nCase = 0;
scanf (%d, nCase);
for (int i = 0; i nCase; ++i)
{
int N = 0;
int H = 0;
scanf (%d%d, N, H);
Solve (a, N, 0, H);
}
}
On May 16, 7:07 pm, mirchi [EMAIL PROTECTED] wrote:
the link ishttp://acm.uva.es/p/v7/729.html
try the problem..
mine is giving a wrong answer...
but my output seems to be fine.
#includestdio.h
#includestdlib.h
#includestring.h
struct strin
{
char st[20];
struct strin * next;};
typedef struct strin stri;
void func (int k , int m , int r , int n , char *str , int count ,stri
**first);
void add(char *str,stri **first);
void prin(stri **first);
int main()
{
stri *first=NULL;
int i,count=0;
int noi,ij;
int r,n;
char *str;
scanf(%d,noi);
for(ij=0;ijnoi;ij++)
{
scanf(%d %d,n,r);
str=(char *)malloc(sizeof(char)*(n+1));
for(i=0;in;i++)
{
str[i]='0';
}
str[n]='\0';
func(0,n-r,r,n,str,count,first);
prin(first);
printf(\n);
first=NULL;
}
system(pause);
return 0;}
void func (int k , int m , int r , int n , char *str,int count,stri
**first)
{
int i,j ;
if(count==(r-1))
{
for(j=k;jn;j++)
{
str[j]='1';
if(j!=k)
str[j-1]='0';
add(str,first);
}
str[j-1]= '0';
return ;
}
else
{
for(i=k;i=m;i++)
{
str[i]='1';
if(i!=k)str[i-1]='0';
func(i+1,m+1,r,n,str,count+1,first);
}
}}
void add(char *str,stri **first)
{
static stri *p=NULL;
if((*first)==NULL)
{
*first=(stri *)malloc(sizeof(stri));
strcpy((*first)-st,str);
(*first)-next=NULL;
p=*first;
}
else
{
(p-next)=(stri *)malloc(sizeof(stri));
p=p-next;
strcpy(p-st,str);
p-next=NULL;
}}
void prin(stri **first)
{
if((*first)==NULL)
return;
else
{
prin(((*first)-next));
printf(%s\n,(*first)-st);
}
}
On May 16, 2:16 pm, Dhruva Sagar [EMAIL PROTECTED] wrote:
I don't know about this...Can you tell me the site where your trying to
submit this problem?
Is it some local (LAN) setup where you are having this submissions as a
part
of some competition or is it in the internet? If in the internet give me
the
link i'll see if i can find something...
On 5/16/07, mirchi [EMAIL PROTECTED] wrote:
u r rite..but now tht prblem is solved the problem i am facing to
submit the code is that it does not print the code in lexicographical
order...
On May 16, 1:56 pm, Dhruva Sagar [EMAIL PROTECTED] wrote:
str[n]=NULL;
I think it should be str[n-1]='\0'; (String null character).
And the loop should run from i=0;in-1.
The memory allocated would be of size n, i.e. 0 to n-1. str[n] would
be
outside the allocated memory...
Correct me if i m wrong.
-- Forwarded message --
From: mirchi [EMAIL PROTECTED]
Date: May 16, 2007 2:20 PM
Subject: [algogeeks] Re: acm problem : i need help
To: Algorithm Geeks algogeeks@googlegroups.com
that problem is solved..but now the reply is wrong answer.
the problem asks for printing the strings in ascending lexicographical
order.
wat