SGU167 I-country
来源:互联网 发布:那个软件接收香港电台 编辑:程序博客网 时间:2024/05/22 21:03
这里写链接内容
记录答案的方法很好。
只需要记录(l,r,opl,opr)即可,而(l,r,opl,opr)都是不超过16的数,那么可以用一个int16进制存下。
附代码
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int n,m,k,ans,a1,a2,a3,a4,a5,cnt;int sum[20][20],f[20][230][20][20][2][2],a[20][230][20][20][2][2];struct data{ int h,z;}dt[230];//f[row][i][l][r][x][y] x/y为0表示增,为1表示减 void add(int ro,int ii,int ll,int rr,int xx,int yy){ if(ro==n) return; for(int i=(!xx?1:ll);i<=rr;i++) for(int j=max(i,ll);j<=(!yy?rr:m);j++){ int t1,t2; if(i==ll) t1=xx; else t1=(i<ll?0:1); if(j==rr) t2=yy; else t2=(j<rr?0:1); if(f[ro+1][ii+j-i+1][i][j][t1][t2]<f[ro][ii][ll][rr][xx][yy]+sum[ro+1][j]-sum[ro+1][i-1]){ f[ro+1][ii+j-i+1][i][j][t1][t2]=f[ro][ii][ll][rr][xx][yy]+sum[ro+1][j]-sum[ro+1][i-1]; a[ro+1][ii+j-i+1][i][j][t1][t2]=(ll<<12)+(rr<<8)+(xx<<4)+(yy); } } }void print(int ro,int ll,int rr,int xx,int yy,int kk){ if(!ro||!kk) return; for(int i=ll;i<=rr;i++) dt[++cnt].h=ro,dt[cnt].z=i; print(ro-1,(a[ro][kk][ll][rr][xx][yy]>>12)%16,(a[ro][kk][ll][rr][xx][yy]>>8)%16,(a[ro][kk][ll][rr][xx][yy]>>4)%16,a[ro][kk][ll][rr][xx][yy]%16,kk-rr+ll-1);}bool cmp(const data&aa,const data&bb){ if(aa.h!=bb.h) return aa.h<bb.h; if(aa.z!=bb.z) return aa.z<bb.z;}int main(){ scanf("%d%d%d",&n,&m,&k); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) scanf("%d",&sum[i][j]),sum[i][j]+=sum[i][j-1]; memset(f,-1,sizeof(f)); ans=-1; for(int row=1;row<=n;row++) for(int l=1;l<=m;l++) for(int r=1;r<=m;r++) for(int x=0;x<=1;x++) for(int y=0;y<=1;y++){ f[row][r-l+1][l][r][x][y]=sum[row][r]-sum[row][l-1]; for(int i=r-l+1;i<=k;i++) if(f[row][i][l][r][x][y]>0){ add(row,i,l,r,x,y); if(i==k&&f[row][i][l][r][x][y]>ans){ ans=f[row][i][l][r][x][y]; a1=row; a2=l; a3=r; a4=x; a5=y; } } } printf("Oil : %d\n",ans); print(a1,a2,a3,a4,a5,k); sort(dt+1,dt+cnt+1,cmp); for(int i=1;i<=cnt;i++) printf("%d %d\n",dt[i].h,dt[i].z); return 0;}
阅读全文
0 0
- sgu167:I-country
- SGU167 I-country
- SGU167
- SGU 167 I-country(DP)
- I vow to thee My country 歌词
- country road takes me home to the place I belong
- country.c
- Square Country
- Country Codes
- Country Code
- Square Country
- Abandoned country
- Abandoned country
- hihocoder1391 Country
- Abandoned country
- Country Codes v2.7.0
- Country ISO CODE
- 中立国 neutral country
- ES(elasticsearch)搜索引擎安装和使用
- Gym-101353H Simple Path(树型dp)
- 朴素贝叶斯分类的Python实现
- java--单测
- linux下如何查看某软件是否已安装
- SGU167 I-country
- POI之Word文档读取-yellowcong
- HDU-5977 Garden of Eden(树分治+枚举子集)
- JS中style.display和style.visibility的区别
- 关于const引用
- Mac Install Raspberry system to machine
- linux ftp 550 Permission denied. ftp Passive mode refused.
- 刷机步骤
- CodeForces830C-Round#424 Div1 C Solution:分块导学&膜QC霸霸