ZOJ1100 状压DP +深搜
来源:互联网 发布:淘宝消保标志 编辑:程序博客网 时间:2024/05/16 11:56
记得做过类似于这类题目是可以用组合数学方法来解决的,可惜淡忘了,也找不到了,看了网上的也有人提到过可以用组合公式解决,可是没人做,都是用了状压DP的方法,这个状压很难讲清楚吧,推荐两篇
第一遍大体看看这个:http://blog.csdn.net/crux_d/article/details/2206736
想要具体实现的时候看看他的解析:http://blog.csdn.net/yan_____/article/details/8719748
#include<iostream>#include<cstdio>#include<list>#include<algorithm>#include<cstring>#include<string>#include<queue>#include<stack>#include<map>#include<vector>#include<cmath>#include<memory.h>#include<set>#include<cctype>#define ll long long#define LL __int64#define eps 1e-8#define inf 0xfffffff//const LL INF = 1LL<<61;using namespace std;//vector<pair<int,int> > G;//typedef pair<int,int > P;//vector<pair<int,int> > ::iterator iter;////map<ll,int >mp;//map<ll,int >::iterator p;ll dp[12][10000];//第i行状态为j的放置方法数int binary[15000][2];//[i][0]表示当前这一行的状态,[i][1]表示与[i][0]相匹配的下一行的状态,因为竖着放会影响下一行int w,h,cnt;void init() {cnt = 0;memset(dp,0,sizeof(dp));}void dfs(int n,int now,int nex) {if(n > w)return;//还有个n+2的,所以有可能直接大于w,而不会产生等于wif(n == w) {binary[cnt][0] = now;binary[cnt++][1] = nex;return;}dfs(n+2,(now<<2) + 3,(nex<<2) + 3);dfs(n+1,(now<<1) + 1,nex<<1);dfs(n+1,now<<1,(nex<<1) + 1);}int main() {while(scanf("%d %d",&w,&h),w + h) {init();dfs(0,0,0);dp[0][(1<<w) - 1] = 1;//边界要填满1for(int i=0;i<h;i++)for(int j=0;j<cnt;j++)dp[i+1][binary[j][1]] += dp[i][binary[j][0]];//下一行的与当前一行的相匹配,所以可递推printf("%lld\n",dp[h][(1<<w) - 1]);}return 0;}
0 0
- ZOJ1100 状压DP +深搜
- poj 2411 zoj1100
- 状压dp
- 状压dp
- 状压dp
- 状压DP
- 状压DP
- 状压DP
- 状压dp
- 状压DP
- 状压DP
- 状压dp
- 状压dp
- 状压dp
- 状压DP
- 状压DP
- 状压DP
- 状压DP
- halcon学习笔记——机器视觉工程应用的开发思路
- 计算机 十进制 二进制 关系
- Data Guard Switchover Unix shell script
- spring resource资源
- ojX
- ZOJ1100 状压DP +深搜
- 用Scheme来写二分查找
- 课程设计之职工工资的管理系统
- Global.asax.cs中的方法的含义
- IOS的处理touch事件处理(依照手指的移动移动一个圆,开发环境用的ios7,storyboard)
- Linux(CentOS6.4)Solr4.8.1中文分词配置(IK分词)
- Python数字
- [NSFileManager defaultManager] 与[[NSFileManager alloc] init]的区别分析
- Android关于AndroidManifest.xml详细分析