Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- ofstream g("bara.out");
- unsigned int L,n,suma=0;
- unsigned int bara[100],st[100];
- void init(int k)
- {
- if(k==1)
- st[k]=0;
- else
- st[k]=st[k-1]-1;
- }
- int surjectiva(int k)
- {
- bool ok;
- for(int i=1;i<=n;i++)
- {
- ok = false;
- for(int j=1;j<=k;j++)
- if(bara[i] == bara[st[j]])
- ok = true;
- if(!ok)
- return 0;
- }
- return 1;
- }
- int succesor(int k)
- {
- if(st[k] < n )
- {
- st[k] ++;
- return 1;
- }
- else
- {
- suma -= bara[st[k-1]];
- return 0;
- }
- }
- int valid(int k)
- {
- if(bara[st[k]] + suma <= L)
- {
- suma +=bara[st[k]];
- return 1;
- }
- return 0;
- }
- int solutie(int k)
- {
- return suma == L;
- }
- void tipar(int k)
- {
- int este = 1;
- g << "#";
- for(int i = 1; i < k; i++)
- {
- cout<<bara[st[i]]<<" ";
- for(int j = 1; j < bara[st[i]]; j++)
- g << "-";
- g << "|";
- }
- for(int i = 1; i<bara[st[k]]; i++)
- g << "-";
- g << "#";
- g << "\n\n\n";
- suma -= bara[st[k]];
- cout<<bara[st[k]];
- cout<<'\n';
- }
- void bkt(int k)
- {
- init(k);
- while(succesor(k))
- if(valid(k))
- if(solutie(k) && surjectiva(k))
- tipar(k);
- else
- bkt(k+1);
- }
- void Citire(){
- ifstream f("bara.in");
- f>>L;f>>n;
- for(int i=1;i<=n;i++)
- {
- f>>bara[i];
- }
- bkt(1);
- f.close();
- }
- int main()
- {
- Citire();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement