topic background BackgroundNo
Title Description DescriptionHead office has a high-efficiency equipment m, ready to be assigned to the subordinate's N branch. If each branch company obtains these equipment, may provide the country certain profit. Q: How can I allocate this m device to make the country the most profitable? Find the maximum profit value. Which m≤15,n≤10. Allocation principle: Each company has the right to obtain any number of equipment, but the total number of units does not exceed the number of devices M.
input/output format input/output
Input Format:
The first line has two numbers, the first number is the branch number n, the second number is the number of units m.
Next is a matrix of n*m, which shows that the first company allocates the profit of the J machine.
output Format:
1th behavior Maximum profit value
2nd to nth for Division I branch x Taiwan
input and Output sample sample Input/output
sample Test point # #
Input Sample:
3 3
30 40 50
20 30 50
20 25 30
Sample output:
70
1 1
2 1
3 1
Code:
/*Note the meaning of the matrix: not a machine, but the benefits of having multiple machines at the same time*/#include<iostream>using namespacestd; #include<cstdio>intn,m,a[ One][ -],f[ One][ -];intsum[ One];voidinput () {scanf ("%d%d", &n,&m);//N Company M Jiqi for(intI=1; i<=n;++i) { for(intj=1; j<=m;++j) scanf ("%d",&A[i][j]); f[i][1]=max (a[i][1],f[i-1][1]); } for(intI=1; i<=m;++i) f[1][i]=a[1][i];}voiddp () { for(intI=2; i<=n;++i) for(intj=1; j<=m;++j) for(intt=1; t<=j;++t) {if(f[i][j]>f[i-1][T]+A[I][J-T])Continue; F[I][J]=f[i-1][t]+a[i][j-T]; Sum[i]=j-t;/*record the number of machines that I have in the company*/ } intn=0; for(intI=2; i<=n;++i) N+=Sum[i]; sum[1]=m-N; cout<<f[n][m]<<Endl; for(intI=1; i<=n;++i) printf ("%d%d\n", I,sum[i]);}intMain () {input (); DP (); return 0;}
View Code
Rokua P2066 Machine Assignment