POJ1296
Posted mxrmxr
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了POJ1296相关的知识,希望对你有一定的参考价值。
#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #include<queue> #include<cmath> #include<vector> #define maxn 40005 #define rint register int #define inf 0x3f3f3f3f #define pb push_back #define mod (int)1e9 + 7 using namespace std; inline int read() { char c=getchar();int x=0,f=1; while(c<‘0‘||c>‘9‘){if(c==‘-‘)f=-1;c=getchar();} while(c>=‘0‘&&c<=‘9‘){x=x*10+c-‘0‘;c=getchar();} return x*f; } inline void write(int x) { if(x<0) putchar(‘-‘),x=-x; if(x>9) write(x/10); putchar(x%10+‘0‘); return ; } int n, m, t, ans; int a[55][55], dp[55][2505], f[55][55][2505], sum0[maxn], sum1[maxn], pre[2][55][55]; //f[i][j][k]表示第i行到第j格用了k次最多染对数,dp[i][k]表示到第i行用了k次最多染对数 char c; inline int max(int a, int b) { return a > b ? a : b; } signed main() { n = read(), m = read(), t = read(); for (rint i = 1; i <= n; ++i) for (rint j = 1; j <= m; ++j) { scanf("%1d", &a[i][j]); pre[ a[i][j] ][i][j] = pre[ a[i][j] ][i][j - 1] + 1; pre[ a[i][j] ^ 1 ][i][j] = pre[ a[i][j] ^ 1 ][i][j - 1]; } for (rint i = 1; i <= n; ++i) for (rint j = 1; j <= m; ++j) for (rint k = 1; k <= m; ++k) for (rint l = 0; l < j; ++l) { f[i][j][k] = max(f[i][j][k], f[i][l][k - 1] + pre[1][i][j] - pre[1][i][l]); f[i][j][k] = max(f[i][j][k], f[i][l][k - 1] + pre[0][i][j] - pre[0][i][l]); } for (rint i = 1; i <= n; ++i) for (rint j = 1; j <= t; ++j) for (rint k = 0; k <= min(m, j); ++k) dp[i][j] = max(dp[i][j], dp[i - 1][j - k] + f[i][m][k]), ans = max(ans, dp[i][j]); write(ans); return 0; }
以上是关于POJ1296的主要内容,如果未能解决你的问题,请参考以下文章
消除keil编译警告 #1296-D:extended constant initialiser used