This problem is similar to the previous 2870 test instructions, but there are many functions that can exchange two columns at any one//start not seeing can exchange two columns ... Results bare samples are not, and finally think of//Exchange two columns, then we can directly to the first row of the column J cnt[i][j]//this line to wake up the sort can be, where cnt[i][j] is the first I row J column has how many//the same 1, in descending order to get a[j], So the maximum value of a[j]*j is the answer that I/I want, because J is definitely above J in front. The comments section is my previous 2870 of naked code, specifically can see my blog dp46 Road Special //Hey, continue to practice it ... #include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cfloat > #include <climits> #include <cmath> #include <complex> #include <cstdio> #include < cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <vector> #define CEIL (A, B) (((a) + (b)-1)/(c)) #define Endl ' \ n ' #define GCD __gcd#define highbit (x) (1ull<< (63-__builtin_clzll (x))) #define Popcount __builtin_popcountlltypedef Long Long ll;using namespace Std;const int MOD = 1000000007;const long double PI = ACOs ( -1.L), template<class t> inline T LCM (const t& A, const t& b) {return A/GCD (A, b) *b;} Template<class t> Inline T lowbit (const t& x) {return x&-x;} Template<class t> inline T maximize (t& A, const t& b) {return a=a<b?b:a;} Template<class t> inline T Minimize (t& A, const t& b) {return a=a<b?a:b;} const int MAXN = 1024;char mp[maxn][maxn];int cnt[maxn][maxn];int l[maxn];int r[maxn];int n,m;int ans;int a[maxn];bool CMP (int a,int b) {return a>b;} void Init () {for (int i=1;i<=n;i++) scanf ("%s", mp[i]+1),//for (int i=1;i<=n;i++)//printf ("%s\n", mp[i]+1); memset (Cnt,0,sizeof (CNT)); ans = 0;} void Solve () {for (int. i=1;i<=n;i++) {for (int j=1;j<=m;j++) {L[j] = r[j] = j;if (mp[i][j]== ' 1 ') cnt[i][j] = Cnt[i-1][j] +1;else Cnt[i][j] = 0;} for (int j=1;j<=m;j++) a[j] = Cnt[i][j];sort (a+1,a+m+1,cmp);//for (int j=2;j<=m;j++) {//if (!cnt[i][j]) continue;/ /while (Cnt[i][l[j]-1]>=cnt[i][j])//l[j] = l[l[j]-1];//}//for (intj=m-1;j>=1;j--) {//if (!cnt[i][j]) continue;//while (Cnt[i][r[j]+1]>=cnt[i][j])//r[j] = r[r[j]+1];//}for (int j= 1;j<=m;j++) {//if (!cnt[i][j]) Continue;ans = max (ANS,A[J]*J);}} printf ("%d\n", ans);} int main () {//freopen ("G:\\code\\1.txt", "R", stdin), while (scanf ("%d%d", &n,&m)!=eof) {init (); Solve ();} return 0;}
HDU 2830 Matrix swapping II DP dynamic programming