广场铺砖问题
来源:互联网 发布:日本看中国网络语言 编辑:程序博客网 时间:2024/06/10 01:42
广场铺砖问题
Description
有一个
Input
只有一行
Output
只有
Sample Input
2 4
Sample Output
5
Solution
用
预处理两个状态之间的关系,即上下行之间的关系。然后用DP,统计可以达到当前行这样状态的数量。
Code
#include <iostream>#include <cstdio>#include <cstring>#define LL long longusing namespace std;LL cnt,w,h,MAXN,ans,oo;bool can[5000][5000];LL num[5000];LL head[5000];LL nxt[100000];LL data[100000];LL f[5000][20];void add(LL x,LL y){ nxt[cnt]=head[x];data[cnt]=y;head[x]=cnt++;}void dfs(LL pre,LL step,LL now){ if(step==h){ if(!can[now][pre]){ can[now][pre]=true; add(now,pre); } return; } if(pre&(1<<step)){ dfs(pre,step+1,now); } else{ dfs(pre,step+1,now|(1<<step)); if(!(pre&(1<<(step+1)))&&step<h-1)dfs(pre,step+2,now); }}LL dp(LL x,LL y){ LL sum=0; if(f[x][y]!=oo)return f[x][y]; if(y==0)return x==0?1:0; for(LL i=head[x];i!=-1;i=nxt[i]){ LL tmp=dp(data[i],y-1); sum+=tmp; } return f[x][y]=sum;}int main(){ freopen("floor.in","r",stdin); freopen("floor.out","w",stdout); memset(f,0x3f,sizeof f);oo=f[0][0]; memset(head,-1,sizeof head); scanf("%lld%lld",&w,&h);MAXN=(1<<(h)); for(LL i=0;i<MAXN;i++) dfs(i,0,0); LL tmp=dp(0,w); ans+=tmp; printf("%lld\n",ans); return 0;}
0 0
- 广场铺砖问题
- 广场铺砖问题
- 【插头DP】广场铺砖
- 【动态规划】广场铺砖
- NKOI 1466 广场铺砖
- 激情广场
- 秋水广场
- 广场舞
- 汇泉广场夜景
- 人民广场,上海博物馆
- 文化广场随笔.
- 运河文化广场
- 我们的广场
- 广场协议事件一览表
- 群光广场美食
- 1002 祭祀广场
- 北航1002-祭祀广场
- 1002 祭祀广场
- Android5.0 WebView中Http和Https混合问题
- 监听TabBar点击事件 使系统tabar的item 点击刷新页面 swift版
- angularJS 下拉框动态绑定后,选择指定值
- FragmentPagerAdapter与FragmentStatePagerAdapter使用详解与区别
- IOS-8-Xcode6 使用MJRefresh报错:Too many arguments to function call, expected 0, have 3
- 广场铺砖问题
- Golang1.7 Goroutine源码分析
- Largest Divisible Subset
- assert是做什么的
- 小鸟云调研活动获奖名单
- 用c语言编写猜随机数的游戏
- daemontools
- Android 四大组件Broadcast
- 同一进程内多个线程状态的查看