First of all, the result must be to take some whole line, plus an extra line of the first few.
If:
X1<=x2<=x3<=x4<=x5
Y1<=y2<=y3<=y4<=y5
Take 6, the optimal solution is to take x3,x4,x5,y3,y4,y5. So:
(1) If y3>=x2, then y3+y4>=x1+x2. Take off the y3,y4 to take x1,x2 more excellent.
(2) If y3<x2, that X3 >y2, then remove x3,x4 take y1,y2 more excellent.
Therefore, the result does not appear 2 lines of the whole. Given the conditions, the number of rows to be taken is also determined. A few more (recorded as K) are also determined. that uses sum[i] to record the row when it is rounded, maxk[i] records the result of the maximum k for that row. The problem is that a row is a whole line and cannot be the first K. This is not greedy, can give counter-examples.
Like what
1 1 1 1
0 0 0 5
Take 5 of them.
This can only be DP. DP[I][J][0] Record the first row, take the J whole line, not to take the smallest extra rows. DP[I][J][1] Records the first row, took the J whole line, has taken the extra rows of the smallest. Then line I can be taken as a whole line, dp[i][j][0]=dp[i-1][j-1][0]+sum[i]. can also not take, indicating that i-1 line has been a whole row of J. Can also be taken as extra rows. Note that you will not be able to get to the point at the beginning of the solution, give a large value.
//#pragma COMMENT (linker, "/stack:1024000000,1024000000")#include <iostream>#include<cstdio>#include<string>#include<cstring>#include<vector>#include<cmath>#include<queue>#include<stack>#include<map>#include<Set>#include<algorithm>#include<stack>#include<iomanip>using namespaceStd;typedefLong LongLon;ConstLon sz=527000, inf=0x7FFFFFFF;Const Doubleeps=1e-8; Vector<lon> vct[1010];lon sum[1010],maxk[1010];lon dp[1010][1010][2];intMain () {//std::ios::sync_with_stdio (0); //freopen ("D:\\1.txt", "R", stdin); //for (; scanf ("%d", &n)!=eof;){lon n,m,k; CIN>>n>>m>>K; Lon Rem=k%m,num=k/m; for(Lon I=1; i<=n;++i) {vct[i].assign (M,0); for(Lon j=0; j<m;++j) cin>>vct[i][j],sum[i]+=Vct[i][j]; Sort (Vct[i].begin (), vct[i].end (), Greater<lon>()); //for (int j=0;j<vct[i].size (); ++j) cout<<vct[i][j]<< ""; //cout<<vct[i].size () << "" <<endl; for(Lon j=0; j<rem;++j) maxk[i]+=Vct[i][j]; //cout<<maxk[i]<<endl;} memset (DP,0x3f,sizeof(DP)); //For (Lon I=0;i<=num;++i) dp[0][i][1]=0x3f3f3f3f,dp[0][i][0]=0x3f3f3f3f;dp[0][0][0]=0; for(Lon I=1; i<=n;++i) { for(Lon j=0; J<=min (i,num); + +j) {if(j==0) dp[i][j][0]=0; Elsedp[i][j][0]=min (dp[i-1][j][0],dp[i-1][j-1][0]+Sum[i]); dp[i][j][1]=min (dp[i-1][j][1],dp[i-1][j][0]+Maxk[i]); dp[i][j][1]=min (dp[i][j][1],dp[i-1][j-1][1]+Sum[i]); //cout<<i<< "<<j<<" "<<dp[i][j][0]<<" "<<dp[i][j][1]<<" < <maxk[i]<<endl; } } if(rem==0) cout<<dp[n][num][0]<<Endl; Elsecout<<dp[n][num][1]<<Endl; } return 0;}
Wannafly Challenge-B Ghost Earth Chasing Soul