BZOJ1187: [HNOI2007]神奇游乐园
发布日期:2021-05-06 03:50:35 浏览次数:27 分类:精选文章

本文共 5512 字,大约阅读时间需要 18 分钟。

Day1前挖的坑现在才补好…

就是一个三进制描述状态..

感觉最近状态不是很好啊..还是好好准备一下市统测吧
垃圾新高考误我竞赛毁我青春妨我把妹

#include
#include
#include
using namespace std;char c;bool flag;inline void read(int &a){ a=0;do c=getchar();while(c!='-'&&(c<'0'||c>'9')); if(c=='-')flag=true,c=getchar(); while(c<='9'&&c>='0')a=(a<<3)+(a<<1)+c-'0',c=getchar(); if(flag)flag=false,a=-a;}int V[103][13];int n,m;const int INF=1<<29;int f[102][9][3000];bool us[102][9];int Div[9];int getpc(int x,int pos){ return (x/Div[pos])%3;} int pc(int pos,int op){ return op*Div[pos];}int get1(int x,int pos){ int l=x%Div[pos]; if(!l)return -1; while(l
m) return -1; return l/3==1?-1:pos;}int main(){ int i,j,t; read(n),read(m); Div[0]=1; for(int i=1;i<=8;i++) Div[i]=Div[i-1]*3; for(i=1;i<=n;i++) for(j=1;j<=m;j++) read(V[i][j]); int base; int Lim=3; for(int i=1;i<=m;i++) Lim*=3; Lim--; int ans=-INF; for(i=0;i<=n;i++) for(j=0;j<=m;j++) for(t=0;t<=2999;t++) f[i][j][t]=-INF; for(i=1;i<=n;i++) for(j=1;j<=m;j++) for(t=0;t<=Lim;t++) { if(i==3&&j==2&&t==567) t++,t--; int rightpc=t%3,lowpc=getpc(t,j); if(t==0){f[i][j][t]=0;continue;} else { if(i==1&&j==1) if(t^5)continue; else f[i][j][t]=V[i][j]; else if(i==1) { if(lowpc==0) if(rightpc==0) f[i][j][t]=f[i][j-1][t]; else if(rightpc==1) f[i][j][t]=f[i][j-1][t]+V[i][j]; else f[i][j][t]=f[i][j-1][t]+V[i][j]; else if(lowpc==1) if(rightpc==0) f[i][j][t]=f[i][j-1][t-1*Div[j]+1]+V[i][j]; else if(rightpc==1) f[i][j][t]=-INF; else f[i][j][t]=f[i][j-1][t-2-Div[j]]+V[i][j]; else if(rightpc==0) f[i][j][t]=f[i][j-1][t-2*Div[j]+2]+V[i][j]; else if(rightpc==1) f[i][j][t]=-INF; else f[i][j][t]=-INF; } else if(j==1) { if(lowpc==0) if(rightpc==0) f[i][j][t]=f[i-1][m][t]; else if(rightpc==1) f[i][j][t]=f[i-1][m][t-1+Div[j]]+V[i][j]; else f[i][j][t]=f[i-1][m][t-2+2*Div[j]]+V[i][j]; else if(lowpc==1) if(rightpc==0) f[i][j][t]=f[i-1][m][t]+V[i][j]; else if(rightpc==1) f[i][j][t]=-INF; else f[i][j][t]=f[i-1][m][t-2-Div[j]]+V[i][j]; else if(rightpc==0) f[i][j][t]=f[i-1][m][t]+V[i][j]; else if(rightpc==1) f[i][j][t]=-INF; else f[i][j][t]=-INF; } else { if(lowpc==0) if(rightpc==0) { int p1=get1(t,j),p2=get2(t,j); f[i][j][t]=f[i][j-1][t]; if(p1!=-1) f[i][j][t]=max(f[i][j][t],f[i][j-1][t-Div[p1]+2+Div[j]*2]+V[i][j]); if(p2!=-1) f[i][j][t]=max(f[i][j][t],f[i][j-1][t+Div[p2]+1+Div[j]*1]+V[i][j]); f[i][j][t]=max(f[i][j][t],f[i][j-1][t+2+Div[j]*1]+V[i][j]);; } else if(rightpc==1) f[i][j][t]=max(f[i][j-1][t],f[i][j-1][t-1+Div[j]])+V[i][j]; else f[i][j][t]=max(f[i][j-1][t],f[i][j-1][t-2+2*Div[j]])+V[i][j]; else if(lowpc==1) if(rightpc==0) f[i][j][t]=max(f[i][j-1][t],f[i][j-1][t-1*Div[j]+1])+V[i][j]; else if(rightpc==1) f[i][j][t]=-INF; else f[i][j][t]=f[i][j-1][t-2-Div[j]]+V[i][j]; else if(rightpc==0) f[i][j][t]=max(f[i][j-1][t],f[i][j-1][t-2*Div[j]+2])+V[i][j]; else if(rightpc==1) f[i][j][t]=-INF; else f[i][j][t]=-INF; } } } for(i=2;i<=n;i++) for(j=2;j<=m;j++) ans=max(ans,f[i][j-1][1+2*Div[j]]+V[i][j]); printf("%d\n",ans); return 0;}
上一篇:BZOJ3125: CITY
下一篇:BZOJ3492: PA2012 Binary Dodgeball

发表评论

最新留言

第一次来,支持一个
[***.219.124.196]2025年05月12日 13时24分27秒