gan这两题怎么差不多

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL; bool u[];
LL f[][];
int main()
{ int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
if(n==&&m==)break;
int li=(<<m)-; for(int i=;i<=li;i++)
{
int cc=;u[i]=true;
for(int j=m-;j>=;j--)
if(i&(<<j))
{
if(cc%==)u[i]=false;
cc=;
}
else cc++;
if(cc%==)u[i]=false;
} //-------------------------- memset(f,,sizeof(f));f[][]=;
for(int i=;i<=n;i++)
for(int zt=;zt<=li;zt++)
for(int lzt=;lzt<=li;lzt++)
if((lzt&zt)==&&u[lzt|zt]==true)
f[i][zt]+=f[i-][lzt];
printf("%lld\n",f[n][]);
}
return ;
}

poj2311

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL; char ss[][]; int b[];
int f[][][];
int len,z[],d[];
int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)scanf("%s",ss[i]+);
for(int i=;i<=n;i++)
{
b[i]=;
for(int j=;j<=m;j++)
if(ss[i][j]=='H')b[i]^=(<<(j-));
} int li=(<<m)-;len=;
for(int i=;i<=li;i++)
{
int cc=-,dd=;bool bk=true;
for(int j=;j<=m-;j++)
if(i&(<<j))
{
if(j-cc<=){bk=false;break;}
cc=j;dd++;
}
if(bk==true){z[++len]=i;d[len]=dd;}
} //-------------------------- int now=,ans=;f[now][][]=;
for(int i=;i<=n;i++)
{
now^=;
for(int j=;j<=len;j++) if(i==||(!(z[j]&b[i-])))
{
for(int k=;k<=len;k++) if( (!(z[k]&b[i])) && (!(z[j]&z[k])) )
{
f[now][j][k]=;
for(int p=;p<=len;p++) if( (i<=||(!(z[p]&b[i-]))) && (!(z[j]&z[p])) && (!(z[k]&z[p])) )
{
f[now][j][k]=max(f[now][j][k],f[now^][p][j]+d[k]);
}
ans=max(ans,f[now][j][k]);
}
}
}
printf("%d\n",ans);
return ;
}

poj1185

同样0/1区分特殊位置,同样预处理当前行的合法状态,同样用位运算判断合法

还是插头DP有意思哈哈,还很快哩

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
const LL mod=; struct Plug_DP
{
LL f[];
int top;LL sta[],hash[];
void pha(LL s,LL sum)
{
LL x=s%mod;
while(hash[x]!=&&sta[hash[x]]!=s)x=(x+)%mod;
if(hash[x]==)sta[++top]=s,hash[x]=top;
f[hash[x]]+=sum;
}
void clean()
{
top=;
memset(hash,,sizeof(hash));
memset(f,,sizeof(f));
}
}dp[];
LL get_bracket(LL s,LL p)
{
return ((s>>(p-))&);
}
LL set_bracket(LL s,LL p,LL v)
{
s^=(get_bracket(s,p)<<(p-));
s^=(v<<(p-));
return s;
} int n,m;LL ans;
void Plug_DP()
{
int pre=,now=;
dp[now].clean();dp[now].pha(,);
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
swap(pre,now);dp[now].clean();
for(int k=;k<=dp[pre].top;k++)
{
LL s=dp[pre].sta[k],sum=dp[pre].f[k];
LL p=get_bracket(s,j),q=get_bracket(s,j+); if(i==n&&j==m)
{
if((p==&&q==)||(p==&&q==))ans+=sum;
continue;
} if(p==&&q==)
{
if(i!=n)
{
s=set_bracket(s,j,);
s=set_bracket(s,j+,);
dp[now].pha(s,sum);
}
if(j!=m)
{
s=set_bracket(s,j,);
s=set_bracket(s,j+,);
dp[now].pha(s,sum);
}
}
if((p==&&q==)||(p==&&q==))
{
s=set_bracket(s,j,);
s=set_bracket(s,j+,);
dp[now].pha(s,sum);
}
}
}
for(int k=;k<=dp[now].top;k++)dp[now].sta[k]<<=;
}
} int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
if(n==&&m==)break;
ans=;Plug_DP();
printf("%lld\n",ans);
}
return ;
}

poj2311(Plug_DP)

最新文章

  1. javascript(定时函数)
  2. 批量运行R包
  3. TextInfo
  4. 重构笔记---MEF框架(上)
  5. tyvj1213 嵌套矩形
  6. J2EE 第二阶段项目之编写代码(四)
  7. 简单实现兼容各大浏览器的js复制内容到剪切板
  8. 2012第二届GIS制图大赛——公开课技术问题&amp;答疑(珍贵资源哦!)(http://blog.csdn.net/arcgis_all/article/details/8216984)
  9. delphi xe5 android tts(Text To Speech)
  10. bnuoj 27987 Record of the Attack at the Orbit (模拟)
  11. [转]gcc -I -L -l区别
  12. C++对象模型--总结
  13. 一个奇怪的注意事项TNS-12545 TNS-12560 TNS-00515
  14. 588. [NOIP1999] 拦截导弹
  15. iOS-xcode代码统计
  16. 【Android Studio安装部署系列】十六、Android studio在layout目录下新建子目录
  17. day 7-21 pymysql模块
  18. ABP框架系列之五:(Unit Of Work-工作单元)
  19. lightswitch binding custom control
  20. ABPZero中的Name和SurName处理,以及EmailAddress解决方案(完美)。

热门文章

  1. centos下使用shell+expect远程登录主机
  2. 【java基础】(2)Java父类与子类的 内存引用讲解
  3. poj3669 广搜
  4. electron 学习
  5. C# 禁止WebBrowser网页跳转时发出的声音
  6. JQuery特效之心形图片墙
  7. C# 检测dll的新版本号方法
  8. 在 Laravel 应用中使用 pjax 进行页面加速
  9. CryptoJS简单使用(request.js) 拦截器的使用
  10. C++调用Matlab函数求特征值