Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <conio.h>
- #include<graphics.h>
- int A[50][50],column[50],x[50],n,max_hs = 0,count=0,kq[50][50];
- void save_()
- {
- for(int i = 0;i<n;i++)
- kq[count][i] = x[i];
- count++;
- }
- void nhap()
- {
- printf("Nhap vao so nguoi va so viec: ");
- scanf("%d",&n);
- for(int i=0;i<n;i++)
- {
- for(int j=0;j<n;j++)
- {
- printf("Nguoi thu %d lam viec %d voi hieu suat: ", i+1,j+1);
- scanf("%d",&A[i][j]);
- }
- }
- for(int i=0;i<n;i++)
- x[i] = 0;
- }
- void hs_max(int k)
- {
- int i,j;
- if(k>=n)// dieu kien de in
- {
- int hieusuat = 0;
- for(i=0;i<n;i++)
- {
- hieusuat += A[i][x[i]];
- }
- if(hieusuat>=max_hs)
- max_hs = hieusuat;
- }
- else
- {
- for(j=0;j<n;j++)
- {
- if(column[j]==0)
- {
- x[k]=j;
- column[j]=1;
- hs_max(k+1);
- column[j]=0;
- }
- }
- }
- }
- void print_hs_max(int k)
- {
- int i,j;
- if(k>=n)// dieu kien de in
- {
- int hieusuat = 0;
- int max[50][50];
- for(i=0;i<n;i++)
- {
- hieusuat += A[i][x[i]];
- }
- if(hieusuat == max_hs) {
- save_();
- }
- }
- else
- {
- for(j=0;j<n;j++)
- {
- if(column[j]==0)
- {
- x[k]=j;
- column[j]=1;
- print_hs_max(k+1);
- column[j]=0;
- }
- }
- }
- }
- main()
- {
- nhap();
- int x1=70,y2=110;
- int p = 80,q = 120;
- char msg[50];
- // khoi tao do hoa
- int sc = DETECT,mode;
- initgraph(&sc,&mode,"C:\\BC5\\BGI");
- // Chay ham tim hieu suat lon nhat
- hs_max(0);
- // chay ham sap xep cong viec
- print_hs_max(0);
- // in ra man hinh so cach chon
- settextstyle(1,HORIZ_DIR,1);
- sprintf(msg,"Co %d cach chon sao cho hieu suat lon nhat",count);
- outtextxy(60,40,msg);
- // in ra man hinh N và V
- // in ra cach tim duoc
- for(int c = 0;c<count;c++)
- {
- for(int i =0 ;i<n;i++)
- {
- sprintf(msg,"V%d",i+1);
- setcolor(WHITE);
- settextstyle(1, HORIZ_DIR, 1);
- outtextxy(x1,90,msg);
- x1=x1+70;
- sprintf(msg,"N%d",i+1);
- setcolor(WHITE);
- settextstyle(1,HORIZ_DIR,1);
- outtextxy(30,y2,msg);
- y2=y2+80;
- }
- settextstyle(1,HORIZ_DIR,2);
- sprintf(msg,"Cach %d. Nhan phim bat ky de xem cach tiep theo",c+1);
- outtextxy(70,60,msg);
- for(int i=0;i<n;i++)
- {
- for(int j=0;j<n;j++){
- sprintf(msg,"%d",A[i][j]);
- if(j==kq[c][i])
- {
- setcolor(RED);
- settextstyle(1, HORIZ_DIR, 1);
- outtextxy(p,q,msg);
- }
- else{
- setcolor(WHITE);
- settextstyle(1, HORIZ_DIR, 1);
- outtextxy(p,q,msg);
- }
- p = p+70;
- }
- p = 90;
- q = q +80;
- }
- getch();
- cleardevice();
- p=80;
- q=120;
- x1=70;
- y2=110;
- }
- getch();
- closegraph();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement