Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- int x[10],a[10][10],n,m;
- void init(int k)
- {
- x[k]=0;
- }
- int existaSuccesor(int k)
- {
- return x[k]<m;
- }
- int cont(int k)
- {
- for(int i=1;i<=k;i++)
- if(a[i][k]==1 && x[i]==x[k])
- return 0;
- return 1;
- }
- int solutie(int k)
- {
- return k==n;
- }
- void tipar()
- {
- for(int i=1;i<=n;i++)
- switch(x[i])
- {
- case 1: cout<<"Rosu"; break;
- case 2: cout<<"Galben"; break;
- case 3: cout<<"Albastru"; break;
- case 4: cout<<"Mov"; break;
- }
- cout<<endl;
- }
- void back(int k)
- {
- init(k);
- while(existaSuccesor(k))
- {
- x[k]=x[k]+1;
- if(cont(k))
- if(solutie(k))
- tipar();
- else
- back(k+1);
- }
- }
- int main()
- {
- ifstream f("intrare.in");
- cout<<"Cate tari sunt: "; f>>n;
- for(int i=1;i<n;i++)
- for(int j=i+1;j<=n;j++)
- {
- cout<<"Tara "<<i<<" este vecina cu tara "<<j<<"."<<endl;
- f>>a[i][j];
- a[j][i]=a[i][j];
- }
- cout<<"Cate culori sunt: "; cin>>m;
- back(1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment