Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- using namespace std;
- struct margea{
- int cul;
- int stralucire;
- }bile[101],bila;
- int solutie[101], maxim, v[101],n,m;
- int vaz[101];
- int verif(){
- if (bile[v[1]].cul!=bile[v[m]].cul)
- return 1;
- return 0;
- }
- void mutare_bile()
- {
- for (int i=1;i<=m;i++)
- solutie[i]=v[i];
- }
- int comparare()
- {
- for (int i=1;i<=m;i++)
- if(solutie[i]>v[i])
- return 1;
- else
- return 0;
- }
- void bkt(int k, int s){
- int i;
- if (k>m)
- {
- if (verif()==1)
- if (s>maxim || (s==maxim && comparare()==1))
- {
- maxim=s;
- mutare_bile();
- }
- }
- else{
- for (i=1;i<=n;i++)
- {
- if (bile[i].cul != bile[v[k-1]].cul && vaz[i]==0)
- {
- v[k]=i;
- vaz[i]=1;
- bkt(k+1,s+bile[i].stralucire);
- vaz[i]=0;
- }
- }
- }
- }
- int main()
- {
- freopen("colier.in","r",stdin);
- freopen("colier.out","w",stdout);
- int i;
- cin>>n>>m;
- for (i=1;i<=n;i++)
- cin>>bile[i].cul>>bile[i].stralucire;
- bkt(1,0);
- for (int i=1;i<=m;i++)
- cout<<solutie[i]<<" ";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement