Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream.h>
- #include<iomanip.h>
- int fact(int);
- int main()
- {
- cout<<"enter total number of tapes\n";
- int n,j,a[10],c,b[10],sum;
- cin>>n;
- cout<<"enter the time taken for indivisual tapes to play\n";
- for(j=0;j<=n-1;j++)
- cin>>a[j];
- cout<<"the tapes are\n";
- for(int k=1;k<=n;k++)
- cout<<setw(3)<<"T"<<k;
- cout<<"\nthe combinations are:\n";
- k=0;
- for(int i=0;i<=(fact(n)-1)/2;i++)
- {
- sum=0;
- c=n;
- for(j=i+1;j<=n;j++)
- {
- cout<<setw(3)<<"T"<<j;
- sum=sum+(c--)*a[j-1];
- }
- for(j=1;j<=i%n;j++)
- {
- cout<<setw(3)<<"T"<<j;
- sum=sum+(c--)*a[j-1];
- }
- cout<<setw(14)<<" Time taken is="<<sum<<endl;
- b[k]=sum;
- k++;
- sum=0;
- c=n;
- for(j=i%n;j>=1;j--)
- {
- cout<<setw(3)<<"T"<<j;
- sum=sum+(c--)*a[j-1];
- }
- for(j=n;j>=i+1;j--)
- {
- cout<<setw(3)<<"T"<<j;
- sum=sum+(c--)*a[j-1];
- }
- cout<<setw(14)<<" Time taken is="<<sum<<endl;
- b[k]=sum;
- k++;
- }
- int t;
- k--;
- t=b[0];
- for(j=0;j<=5;j++)
- {
- if(t>b[j])
- t=b[j];
- }
- cout<<"the minimal optimum solution is:\n"<<t<<endl;
- return 0;
- }
- int fact(int x)
- {
- int facto=1;
- if(x==1||x==0)
- return 1;
- else
- {
- return x*fact(x-1);
- }
- }
- OUTPUT:
- enter total number of tapes
- 3
- enter the time taken for indivisual tapes to play
- 5
- 10
- 3
- the tapes are
- T1 T2 T3
- the combinations are:
- T1 T2 T3 Time taken is=38
- T3 T2 T1 Time taken is=34
- T2 T3 T1 Time taken is=41
- T1 T3 T2 Time taken is=31
- T3 T1 T2 Time taken is=29
- T2 T1 T3 Time taken is=43
- the minimal optimum solution is:
- 29
Advertisement
Add Comment
Please, Sign In to add comment