Advertisement
Guest User

2256 v2

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