Advertisement
Guest User

2256 - nou

a guest
Feb 18th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. using namespace std;
  4. struct margea{
  5. int cul;
  6. int stralucire;
  7. }bile[101],bila;
  8. int solutie[101], maxim, v[101],n,m;
  9. int vaz[101];
  10. int verif(){
  11. if (bile[v[1]].cul!=bile[v[m]].cul)
  12. return 1;
  13. return 0;
  14. }
  15. void mutare_bile()
  16. {
  17. for (int i=1;i<=m;i++)
  18. solutie[i]=v[i];
  19. }
  20. int comparare()
  21. {
  22. for (int i=1;i<=m;i++)
  23. if(solutie[i]>v[i])
  24. return 1;
  25. else
  26. return 0;
  27. }
  28. void bkt(int k, int s){
  29. int i;
  30. if (k>m)
  31. {
  32. if (verif()==1)
  33. if (s>maxim || (s==maxim && comparare()==1))
  34. {
  35. maxim=s;
  36. mutare_bile();
  37. }
  38. }
  39. else{
  40. for (i=1;i<=n;i++)
  41. {
  42. if (bile[i].cul != bile[v[k-1]].cul && vaz[i]==0)
  43. {
  44. v[k]=i;
  45. vaz[i]=1;
  46. bkt(k+1,s+bile[i].stralucire);
  47. vaz[i]=0;
  48. }
  49. }
  50. }
  51. }
  52. int main()
  53. {
  54. freopen("colier.in","r",stdin);
  55. freopen("colier.out","w",stdout);
  56. int i;
  57. cin>>n>>m;
  58. for (i=1;i<=n;i++)
  59. cin>>bile[i].cul>>bile[i].stralucire;
  60. bkt(1,0);
  61. for (int i=1;i<=m;i++)
  62. cout<<solutie[i]<<" ";
  63. return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement