题意:https://www.nitacm.com/problem_show.php?pid=1378

如题。

思路:

从第一行for到最后一行,枚举每一行的所有状态,进行转移,注意答案是dp【最后一行】【0】,因为最后一行是唯一确定的。

https://blog.csdn.net/Tc_To_Top/article/details/43891119

 #define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#include <cstdio>//sprintf islower isupper
#include <cstdlib>//malloc exit strcat itoa system("cls")
#include <iostream>//pair
#include <fstream>//freopen("C:\\Users\\13606\\Desktop\\草稿.txt","r",stdin);
#include <bitset>
//#include <map>
//#include<unordered_map>
#include <vector>
#include <stack>
#include <set>
#include <string.h>//strstr substr
#include <string>
#include <time.h>//srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
#include <cmath>
#include <deque>
#include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
#include <vector>//emplace_back
//#include <math.h>
//#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
#include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
//******************
int abss(int a);
int lowbit(int n);
int Del_bit_1(int n);
int maxx(int a,int b);
int minn(int a,int b);
double fabss(double a);
void swapp(int &a,int &b);
clock_t __STRAT,__END;
double __TOTALTIME;
void _MS(){__STRAT=clock();}
void _ME(){__END=clock();__TOTALTIME=(double)(__END-__STRAT)/CLOCKS_PER_SEC;cout<<"Time: "<<__TOTALTIME<<" s"<<endl;}
//***********************
#define rint register int
#define fo(a,b,c) for(rint a=b;a<=c;++a)
#define fr(a,b,c) for(rint a=b;a>=c;--a)
#define mem(a,b) memset(a,b,sizeof(a))
#define pr printf
#define sc scanf
#define ls rt<<1
#define rs rt<<1|1
typedef long long ll;
const double E=2.718281828;
const double PI=acos(-1.0);
//const ll INF=(1LL<<60);
const int inf=(<<);
const double ESP=1e-;
const int mod=(int)1e9+;
const int N=(int)1e5+; ll dp[][N];
bool ok(int x,int l)
{
bool f=;
int cnt=;
for(int i=;i<=l-;++i)
{
if((x>>i)&)
{
if(cnt&)
return ;
}
else
cnt++;
}
if(cnt&)f=;
return f;
} int main()
{
int n,m;
while(sc("%d%d",&n,&m),n||m)
{
if(n*m%==)
{
pr("0\n");
continue;
}
int m_=m;
m=<<m;
for(int i=;i<=n;++i)
for(int j=;j<=m;++j)
dp[i][j]=;
dp[][]=;
for(int i=;i<=n;++i)
for(int j=;j<m;++j)
for(int k=;k<m;++k)
if((j&k)==&&ok(j^k,m_))
dp[i][k]+=dp[i-][j];
pr("%lld\n",dp[n][]);
}
return ;
} /**************************************************************************************/ int maxx(int a,int b)
{
return a>b?a:b;
} void swapp(int &a,int &b)
{
a^=b^=a^=b;
} int lowbit(int n)
{
return n&(-n);
} int Del_bit_1(int n)
{
return n&(n-);
} int abss(int a)
{
return a>?a:-a;
} double fabss(double a)
{
return a>?a:-a;
} int minn(int a,int b)
{
return a<b?a:b;
}

骨牌摆放方案数n*m(状压DP)的更多相关文章

  1. BZOJ_2734_[HNOI2012]集合选数_构造+状压DP

    BZOJ_2734_[HNOI2012]集合选数_构造+状压DP 题意:<集合论与图论>这门课程有一道作业题,要求同学们求出{1, 2, 3, 4, 5}的所有满足以 下条件的子集:若 x ...

  2. HDU 1565&1569 方格取数系列(状压DP或者最大流)

    方格取数(2) Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  3. POJ3254 状压dp

                                                                                                    Corn ...

  4. bzoj2734:[HNOI2012]集合选数(状压DP)

    菜菜的喵喵题~ 化序列为矩阵!化腐朽为神奇!左上角为1,往右每次*3,往下每次*2,这样子就把问题转化成了在矩阵里选不相邻的数有几种可能. 举个矩阵的例子 1 3 9 27 2 6 18 54 4 1 ...

  5. 相邻行列相互影响的状态类问题(类似状压dp的搜索)(POJ3279)

    POJ3279http://poj.org/problem?id=3279 题意:黑白的板,每次选择一个十字形翻转(十字板内黑白互换,若是边界则不管),求最小将原图变为全白的策略. 这是一道对于每个格 ...

  6. 多米诺骨牌放置问题(状压DP)

    例题: 最近小A遇到了一个很有趣的问题: 现在有一个\(n\times m\)规格的桌面,我们希望用\(1 \times 2\)规格的多米诺骨牌将其覆盖. 例如,对于一个\(10 \times 11\ ...

  7. hdu 2167 方格取数 【状压dp】(经典)

    <题目链接> 题目大意: 给出一些数字组成的n*n阶矩阵,这些数字都在[10,99]内,并且这个矩阵的  3<=n<=15,从这个矩阵中随机取出一些数字,在取完某个数字后,该数 ...

  8. BZOJ3724 [HNOI2012]集合选数 【状压dp】

    题目链接 BZOJ3724 题解 构造矩阵的思路真的没想到 选\(x\)就不能选\(2x\)和\(3x\),会发现实际可以转化为矩阵相邻两项 \[\begin{matrix}1 & 3 &am ...

  9. 【bzoj2734】集合选数(有点思维的状压dp)

    题目传送门:bzoj2734 这题一个月前看的时候没什么头绪.现在一看,其实超简单. 我们对于每个在$ [1,n] $范围内的,没有因数2和3的数$ d $,将它的倍数$ 2^a 3^b d $一起处 ...

随机推荐

  1. Python基础之range()

    range:指定范围,生成指定数字. 1. range() for i in range(1, 10): print(i) 执行结果为: 1 2 3 4 5 6 7 8 9 2. range()步长 ...

  2. vue-router的两种动态路由

    第一种实质上不能算动态路由,充其量算是参数的传递 https://www.jianshu.com/p/f499d9f64958 第二种是真正的动态路由,利用 router.addRoutes()设置动 ...

  3. maven mvn 命令行 编译打包

    * 配置好jdk * 下载安装maven http://maven.apache.org/download.cgi apache-maven-3.3.3-bin.zip * 解压到G:\apache- ...

  4. 20175329&20175313&20175318 2019-2020 《信息安全系统设计基础》实验一

    详见 https://www.cnblogs.com/xiannvyeye/p/11792152.html#%E4%B8%80%E5%AE%9E%E9%AA%8C%E5%86%85%E5%AE%B9

  5. docker mysql容器的安装使用

    docker拉取镜像的命令为 docker pull image[:TAG] 如果我们想安装的mysql版本不是最新的版本,则需要填充TAG,如果不带上TAG,则默认安装的为最新版本,虽然可以通过do ...

  6. LC 881. Boats to Save People

    The i-th person has weight people[i], and each boat can carry a maximum weight of limit. Each boat c ...

  7. TCP怎么保证证包有序传输的,TCP的慢启动,拥塞避免,快速重传,快速恢复

    TCP提供了最可靠的数据传输,它给发送的每个数据包做顺序化(这看起来非常烦琐),然而,如果TCP没有这样烦琐的操作,那么,可能会造成更多的麻烦.如造成数据包的重传.顺序的颠倒甚至造成数据包的丢失. 那 ...

  8. Fluent Ribbon Control Suite和AvalonDock 控件库

    Fluent Ribbon Control Suite 是一个Ribbon控件,可以用来创建Office 2010 样式的用户界面,支持MVVM,最近快要更新了,将会有Office 2013 样式的主 ...

  9. ES6拓展符修改对象

    // ES6 拓展符合并两个对象let ab = { ...a, ...b }; // 等同于 let ab = Object.assign({}, a, b); // 修改对象部分属性.用户自定义的 ...

  10. 在centos卸载mysql

    1 rpm -qa|grep mysql 查看安装了哪些mysql和lib…… 1 yum remove mysql mysql-server mysql-libs compat-mysql51 删除 ...