首页 > 其他分享 >poj 2411 状压dp入门题

poj 2411 状压dp入门题

时间:2023-11-01 19:36:16浏览次数:33  
标签:状态 状压 2411 poj dp include rectangles rectangle he

Mondriaan's Dream

Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 29096   Accepted: 15505

Description

Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, after producing the drawings in his 'toilet series' (where he had to use his toilet paper to draw on, for all of his paper was filled with squares and rectangles), he dreamt of filling a large rectangle with small rectangles of width 2 and height 1 in varying ways.

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

The input contains several test cases. Each test case is made up of two integer numbers: the height h and the width w of the large rectangle. Input is terminated by h=w=0. Otherwise, 1<=h,w<=11.

Output

For each test case, output the number of different ways the given rectangle can be filled with small rectangles of size 2 times 1. Assume the given large rectangle is oriented, i.e. count symmetrical tilings multiple times.

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

Ulm Local 2000

 

这poj复制下来的题目还挺全awa

很经典的状压dp入门题
dp的状态设计可以说绝定了这个dp的一切,之前的dp的状态设计都是在一定范围内的,都只是用这个数字来表示一个具体的值
而状态压缩的dp的状态可以表示更多的含义
这里就是用一个维度的状态来表示当前列或者是上一列的占用情况
(其实不是占用情况,但是为了好理解,先这么说,其实用01表示竖着的小矩形的开头是否在这个位置)
然后我们就可以在这种状态的表示下进行搜索路径的优化了
(除了位运算比较复杂和难调)
状压dp的共性很明显就是有一个维度的数据量非常小,只能是10这个级别的,稍微大一点就不不行,因为这个东西的时空复杂度都是指数级别的
所以还是非常好分辨的

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <string.h>
#define ll long long
using namespace std;
inline int read() {
    char c=getchar();int a=0,b=1;
    for(;c<'0'||c>'9';c=getchar())if(c=='-')b=-1;
    for(;c>='0'&&c<='9';c=getchar())a=a*10+c-48;return a*b;
}
ll f[12][1<<11];bool chek[1<<11];
int main()
{
//    freopen(".in","r",stdin);
//    freopen(".out","w",stdout);
    int n,m;
    while(1)
    {
        n=read();m=read();
        if(n==0)break;
        for(int i=0;i<1<<m;i++)
        {
            bool ha_odd=0,cnt=0;
            for(int j=0;j<m;j++)
            {
                if((i>>j)&1)//如果有一个1
                {
                    ha_odd|=cnt;
                    cnt=0;
                }
                else cnt^=1;
            }
            chek[i]=(ha_odd|cnt)?0:1;
        }
        f[0][0]=1;
        for(int i=1;i<=n;i++)
        {
            for(int j=0;j<1<<m;j++)//枚举上一个状态的1的位置 ,也就是上一个状态占掉了那些位置
            {
                f[i][j]=0;
                for(int k=0;k<1<<m;k++)//枚举下一个状态有那些竖着的    
                {
                    if((j&k)==0 && chek[j|k])
                    {
                        f[i][j]+=f[i-1][k];
                    }
                }
            }
        }
        cout<<f[n][0]<<endl;
    }
    return 0;
}

能学的主要就是那几个位运算的操作,还有这个预处理的思路,以及状态表示的是是否是竖着的小矩形的开头,这个我原本设计的状态不是这样的,然后很难搞
但是想想我们其实是同时有上下两排的状态的,那确实是只要记录一下开头就可以了,后效性的处理也可通过这种从后往前的方法考虑来消除,也是因为这种操作的后效性有限,如果是无限或者是不可知的那就不行了。
所以可系统的预测的后效性常常可以接受的。学到了

 

标签:状态,状压,2411,poj,dp,include,rectangles,rectangle,he
From: https://www.cnblogs.com/HLZZPawa/p/17803905.html

相关文章

  • java 开发中VO、PO、DO、DTO、BO、QO、DAO、POJO各种傻傻分不清
    VO(ValueObject):值对象,主要用于业务层之间的数据传递,是方法返回类型。例如,一个方法需要返回用户的信息,可以创建一个UserVO,包含用户的姓名、年龄等信息。PO(PersistentObject):持久化对象,用于表示数据库中的一条记录,与数据库表一一对应。例如,数据库中有一个用户表,可以创建一个Use......
  • 浅析POJO、DTO、DO、VO、BO、PO、Entity
    名词解释领域模型中的实体类分为四种模型:VO、DTO、DO和PO,各种实体类用于不同业务层次间的交互,并会在层次内实现实体类之间的转化。新项目使用了新的框架和开发规范,特意集体讨论了DTO,DO,VO,BO,POJO,PO和Entity以及DAO、Model和View的基本概念和使用场景,为了深入理解,这里整理为一篇笔记......
  • POJO
    POJO(PlainOrdinaryJavaObject)简单的Java对象,实际就是普通JavaBeans,是为了避免和EJB混淆所创造的简称。使用POJO名称是为了避免和EJB混淆起来,而且简称比较直接.其中有一些属性及其gettersetter方法的类,没有业务逻辑,有时可以作为VO(value-object)或dto(DataTransformObjec......
  • poj 1742 coins
    DescriptionPeopleinSilverlandusecoins.TheyhavecoinsofvalueA1,A2,A3...AnSilverlanddollar.OnedayTonyopenedhismoney-boxandfoundthereweresomecoins.Hedecidedtobuyaverynicewatchinanearbyshop.Hewantedtopaytheexactprice(wi......
  • poj3666
    #include<iostream>#include<stdio.h>#include<algorithm>#include<cmath>#include<math.h>#include<map>#include<string.h>#definelllonglongusingnamespacestd;intn,a[2001],f[2001][2001],b[2001];inli......
  • poj2279
    Mr.Young'sPicturePermutationsTimeLimit:1000MS MemoryLimit:65536KTotalSubmissions:5841 Accepted:1860DescriptionMr.Youngwishestotakeapictureofhisclass.Thestudentswillstandinrowswitheachrownolongerthanth......
  • The 2nd Universal Cup. Stage 4: Taipei - I(状压DP)
    目录I.IntervalAdditionI.IntervalAddition题意给定一个长度为n$(1\len\le23)$的数组a。你可以进行一种操作:选择区间\([l,r]\)并给这个区间所有的数都加上一个任意的数。问你使得整个数组均为0所需的最小操作次数?思路考虑差分数组无论怎么对于区间\([l,r......
  • 代码源:互不侵犯(SCOI,状压DP)
    点击查看代码#include<bits/stdc++.h>usingnamespacestd;intn,m;longlongf[10][1024][100];intv[1024];voidinit(){ for(inti=1;i<1<<n;++i) { intc=0; for(intj=i;j;j=j&(j-1))c++; v[i]=c; }}intmain(){ ios::sync_with_std......
  • 挑战程序设计竞赛 2.2 poj 2393 Yogurt factory
    https://vjudge.net/problem/POJ-2393奶牛们购买了一家酸奶厂,生产世界闻名的"YuckyYogurt"酸奶。在接下来的N(1<=N<=10,000)周里,牛奶和劳动力的价格每周都会波动,因此在第i周生产一单位酸奶将花费公司C_i(1<=C_i<=5,000)美分。Yucky酸奶厂设计合理,每周可以......
  • 挑战程序设计竞赛 2.2 poj 1328 Radarinstallation
    https://vjudge.net/problem/POJ-1328假设海岸线是一条无限长的直线。陆地在海岸线的一边,海洋在另一边。每个小岛都是位于海边的一个点。而位于海岸线上的任何雷达装置都只能覆盖d的距离,因此,如果两者之间的距离最多为d,那么海中的一个小岛就可以被一个半径为d的装置覆盖。......