bzoj1296 [SCOI2009]粉刷匠

题目链接

背包

两层背包(分组背包)

一个处理一块板子内的情况

一个处理整体的情况

 1 #include<algorithm>
 2 #include<iostream>
 3 #include<cstdlib>
 4 #include<cstring>
 5 #include<cstdio>
 6 #include<string>
 7 #include<cmath>
 8 #include<ctime>
 9 #include<queue>
10 #include<stack>
11 #include<map>
12 #include<set>
13 #define rre(i,r,l) for(int i=(r);i>=(l);i--)
14 #define re(i,l,r) for(int i=(l);i<=(r);i++)
15 #define Clear(a,b) memset(a,b,sizeof(a))
16 #define douin(x) scanf("%lf",&x)
17 #define strin(x) scanf("%s",(x))
18 #define LLin(x) scanf("%lld",&x)
19 #define inin(x) scanf("%d",&x)
20 #define CSC main
21 typedef unsigned long long ULL;
22 typedef const int cint;
23 typedef long long LL;
24 using namespace std;
25 int yp()
26 {
27     int x=0,f=0;char ch=getchar();
28     while(ch<'0'||ch>'9'){if(ch=='-')f=1;ch=getchar();}
29     while(ch>='0'&&ch<='9')x*=10,x+=ch-'0',ch=getchar();
30     return f?-x:x;
31 }
32 int n,m,t,ans,a[55],h[55][55],hh[55][2525];
33 char s[55];
34 int CSC()
35 {
36     n=yp(),m=yp(),t=yp();
37     re(i,1,n)
38     {
39         strin(s+1);
40         re(j,1,m)a[j]=s[j]-'0'+a[j-1];
41         re(j,1,m)re(k,1,m)
42         {
43             h[k][j]=0;
44             re(l,0,k-1)
45             {
46                 int temp=a[k]-a[l];
47                 h[k][j]=max(h[k][j],h[l][j-1]+max(temp,k-l-temp));
48             }
49         }
50         re(j,1,t)re(k,1,min(m,j))
51             hh[i][j]=max(hh[i][j],hh[i-1][j-k]+h[m][k]);
52     }
53     re(i,1,t)ans=max(ans,hh[n][i]);
54     printf("%d\n",ans);
55     return 0;
56 }

 

posted @ 2016-01-22 15:33  HugeGun  阅读(217)  评论(0编辑  收藏  举报