POJ2411(SummerTrainingDay02-I 状态压缩dp)
Mondriaan's Dream
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 17187 | Accepted: 9911 |
Description

Expert as he was in this material, he saw at a glance that he'll need a computer to calculate the number of ways to fill the large rectangle whose dimensions were integer values, as well. Help him, so that his dream won't turn into a nightmare!
Input
Output

Sample Input
1 2
1 3
1 4
2 2
2 3
2 4
2 11
4 11
0 0
Sample Output
1
0
1
2
3
5
144
51205
Source
//2017-08-02
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm> using namespace std; const int N = ;
int n, m;
long long dp[N][<<N];//dp[col][state]表示第col列,在state状态下(即前一列对该列的影响)的方法数。 //dfs表示当前处理到col列的第i个格子,state状态下,对下一列的影响nex
void dfs(int col, int i, int state, int nex){
if(i == n){
dp[col+][nex] += dp[col][state];
return;
}
if((state&(<<i)) > )//这个格子已经被上一列填过
dfs(col, i+, state, nex);
if((state&(<<i)) == )//格子没有被填充,尝试横着放一块砖
dfs(col, i+, state, nex|(<<i));
if(i+<n && (state&(<<i))== && (state&(<<(i+)))==)//尝试竖着放一块砖
dfs(col, i+, state, nex);
} int main(){
while(cin>>n>>m){
if(!n && !m)break;
memset(dp, , sizeof(dp));
dp[][] = ;
for(int col = ; col <= m; col++){
for(int state = ; state < (<<n); state++){
if(dp[col][state])
dfs(col, , state, );
}
}
cout<<dp[m+][]<<endl;//答案为第m+1列,前一列对其影响为0的方法数。
} return ;
}
POJ2411(SummerTrainingDay02-I 状态压缩dp)的更多相关文章
- 状态压缩dp(hdu2167,poj2411)
hdu2167 http://acm.hdu.edu.cn/showproblem.php?pid=2167 给定一个N*N的板子,里面有N*N个数字,选中一些数字,使得和最大 要求任意两个选中的数字 ...
- DP大作战—状态压缩dp
题目描述 阿姆斯特朗回旋加速式阿姆斯特朗炮是一种非常厉害的武器,这种武器可以毁灭自身同行同列两个单位范围内的所有其他单位(其实就是十字型),听起来比红警里面的法国巨炮可是厉害多了.现在,零崎要在地图上 ...
- SGU131 - Hardwood floor(状态压缩DP)
题目大意 给定一个N*M大小的矩形,要求你用1*2和2*2(缺个角)的砖块把矩形铺满(不能重叠),问总共有多少种铺法? 题解 受POJ2411的影响,怎么都没想到3,4,5,6这几种情况该怎么放置,看 ...
- 状态压缩DP(大佬写的很好,转来看)
奉上大佬博客 https://blog.csdn.net/accry/article/details/6607703 动态规划本来就很抽象,状态的设定和状态的转移都不好把握,而状态压缩的动态规划解决的 ...
- hoj2662 状态压缩dp
Pieces Assignment My Tags (Edit) Source : zhouguyue Time limit : 1 sec Memory limit : 64 M S ...
- POJ 3254 Corn Fields(状态压缩DP)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4739 Accepted: 2506 Descr ...
- [知识点]状态压缩DP
// 此博文为迁移而来,写于2015年7月15日,不代表本人现在的观点与看法.原始地址:http://blog.sina.com.cn/s/blog_6022c4720102w6jf.html 1.前 ...
- HDU-4529 郑厂长系列故事——N骑士问题 状态压缩DP
题意:给定一个合法的八皇后棋盘,现在给定1-10个骑士,问这些骑士不能够相互攻击的拜访方式有多少种. 分析:一开始想着搜索写,发现该题和八皇后不同,八皇后每一行只能够摆放一个棋子,因此搜索收敛的很快, ...
- 状态压缩dp问题
问题:Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Ev ...
- BZOJ-1226 学校食堂Dining 状态压缩DP
1226: [SDOI2009]学校食堂Dining Time Limit: 10 Sec Memory Limit: 259 MB Submit: 588 Solved: 360 [Submit][ ...
随机推荐
- adb shell pm list packages的用法
abd shell pm list packages ####查看当前连接设备或者虚拟机的所有包 adb shell pm list packages -d #####只输出禁用的包. ...
- salt-api return mysql返回的使用,记录操作日志
说在前面 折腾这个搞了半天,现做下记录 安装依赖(操作只在master端) yum install mysql-python or pip install mysql-python master端本地 ...
- java中连接各种数据的方法
1.oraclethin驱动连接字符串:jdbc:oracle:thin:用户名/密码@localhost:1521:cake驱动类:oracle.jdbc.driver.OracleDriver 2 ...
- 剑指offer八之跳台阶
一.题目 一只青蛙一次可以跳上1级台阶,也可以跳上2级.求该青蛙跳上一个n级的台阶总共有多少种跳法. 二.思路 a.如果两种跳法,1阶或者2阶,那么假定第一次跳的是一阶,那么剩下的是n-1个台阶,跳法 ...
- 在matlab中实现梯度下降法
梯度下降法的原理,本文不再描述,请参阅其它资料. 梯度下降法函数function [k ender]=steepest(f,x,e),需要三个参数f.x和e,其中f为目标函数,x为初始点,e为终止误差 ...
- Java代码调用Oracle的存储过程,存储函数和包
Java代码调用存储过程和存储函数要使用CallableStatement接口 查看API文档: 上代码: java代码调用如下的存储过程和函数: 查询某个员工的姓名 月薪 职位 create or ...
- c++获取随机数
方法一: 使用 rand 函数可以获取,如下. 随机数大小是在0到RAND_MAX,值为2147483647,它是在stdlib中定义的,如果我们希望在某个范围内,可以使用 % 结合 / 来实现. 但 ...
- 微信小程序开发环境搭建
关注,QQ群,微信应用号社区 511389428 微信小程序可谓是今天最火的一个名词了,一经出现真是轰炸了整个开发人员,当然很多App开发人员有了一个担心,微信小程序的到来会不会给移动端App带来一个 ...
- springboot + mybatis +druid
Druid Spring Boot Starter mybatis-spring-boot-autoconfigure mybatis-spring-boot-samples 新建spring boo ...
- Mybatis 事务管理和缓存机制
一级缓存--SqlSession级别 数据库表tb_user User package com.example.demo.domain; public class User { private Int ...