Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int sol[100],n,nb,nf,m,y,x;
- int valid(int k)
- {/*for(int i=1;i<=k;i++)
- if(sol[i]<=x)
- nf++;
- else nb++;*/
- if(nf>y)
- {
- return 0;
- }
- if(nb>m-y)
- {
- return 0;
- }
- if(sol[k]<=sol[k-1]&&k>1)
- {
- return 0;
- }
- return 1;
- }
- void afis(int k)
- {
- for(int i=1;i<=k;i++)
- {
- cout<<sol[i]<<" ";
- }
- cout<<endl;
- }
- void backt(int k)
- {
- for(int i=1;i<=n;i++)
- {
- sol[k]=i;
- if(sol[k]<=x)nf++;
- else nb++;
- if(valid(k)==1)
- {
- if(k==m)
- {
- afis(k);
- }
- else
- {
- backt(k+1);
- }
- }
- if(sol[k]<=x)nf--;
- else nb--; }
- }
- int main()
- {
- cout<<"n=";
- cin>>n;
- cout<<"m=";
- cin>>m;
- cout<<"y=";
- cin>>y;
- cout<<"x=";
- cin>>x;
- backt(1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement