标签:style 字符串 多少 数组 == 字符 转移 连续 http
3 6 3 111111 000000 001100
16
# include <iostream> # include <cstdio> # include <cstring> using namespace std; char str[52][52]; int dp[52][52]; int blue[52][52],red[52][52]; int f[52][2502]; int n,m,t; int main(){ scanf("%d %d %d",&n,&m,&t); for(int i = 1;i <= n;i++){ scanf("%s",&str[i][1]); } for(int i = 1;i <= n;i++){ for(int j = 1;j <= m;j++){ blue[i][j] = blue[i][j - 1]; red[i][j] = red[i][j - 1]; if(str[i][j] == ‘0‘)blue[i][j]++; else red[i][j]++; } } for(int q = 1; q <= n;q++){ memset(dp,0,sizeof dp); for(int i = 1;i <= min(t,m);i++){ for(int x = 1;x <= m;x++){ for(int y = 0;y < x;y++){ dp[i][x] = max(dp[i][x],dp[i - 1][y] + max(blue[q][x] - blue[q][y],red[q][x] - red[q][y])); } } } for(int i = 1;i <= t;i++){ for(int j = 1;j <= min(i,m);j++){ f[q][i] = max(f[q][i],f[q - 1][i - j] + dp[j][m]); } } } int ans = 0; for(int i = 1;i <= t;i++)ans = max(ans,f[n][i]); printf("%d\n",ans); return 0; }
[Bzoj 1296][Scoi2009] 粉刷匠 [DP + 分组背包]
标签:style 字符串 多少 数组 == 字符 转移 连续 http
原文地址:http://www.cnblogs.com/lzdhydzzh/p/7642671.html