Pagini recente » Cod sursa (job #1839573) | Cod sursa (job #9436)
Cod sursa(job #9436)
#include <IOstream.h>
#include <fstream.h>
ifstream in ("secv5.in");
ofstream out ("secv5.out");
typedef int stiva[100];
int n,m=2,k,ev,as,solution=0;
int N,L,U,a[250];
stiva st;
void init ();
int succesor ();
int valid ();
void print();
int solutie ();
void bt ();
int main ()
{
int i;
in>>N>>L>>U;
n=N;
for (i=0;i<n;i++)
in>>a[i];
bt();
out<<solution;
return 0;
}
void init ()
{
if (k==1)
st[k]=0;
else
st[k]=st[k-1];
}
int succesor ()
{
if (st[k]<n-m+k)
{
st[k]++;
return 1;
}
return 0;
}
int valid ()
{
return 1;
}
int solutie ()
{
return k==m;
}
void print ()
{
int i,j,cont=0,bool;
/*for (i=1;i<=m;i++)
cout<<st[i]<<" ";
cout<<endl;*/
for (i=st[1]-1;i<st[2];i++)
{
bool=1;
for (j=i+1;j<st[2];j++)
if (a[i]==a[j])
bool=0;
if (bool)
cont++;
}
if (cont>=L && cont<=U)
solution++;
}
void bt ()
{
k=1;
init();
while (k>0)
{
as=1;
ev=0;
while (as && !ev)
{
as=succesor();
if (as)
ev=valid();
}
if (as)
if (solutie())
print();
else
{
k++;
init();
}
else
k--;
}
}