poj2441 Arrange the Bulls 状压DP
来源:互联网 发布:淘宝网店服装头像图片 编辑:程序博客网 时间:2024/05/21 08:03
看了下别人的实现感觉不科学写的那么复杂然而速度是我的1/2= =
我们看到这个很容易联想到棋盘模型n*m,放置n个车,问方案数.
然后愉快地做就行,最简复杂度O(n*2^m),然而窝写成O(m*2^m)其实也无所谓
Problem: 2441User: BPM136Memory: 4812KTime: 235MSLanguage: G++Result: Accepted#include<iostream>#include<cstdio>#include<bitset>#define LL long long#define fo(i,a,b) for(int i=a;i<=b;i++)using namespace std;inline LL read(){LL d=0,f=1;char s=getchar();while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}while(s>='0'&&s<='9'){d=d*10+s-'0';s=getchar();}return d*f;}#define N 25#define M 20unsigned long f[1<<M]={1};bool map[N][N];int n,m;bitset<N>t;int main(){n=read(),m=read();if(n>m){puts("0");return 0;}fo(i,1,n){int k=read();while(k--)map[i][read()]=1;}LL ans=0;fo(i,1,(1<<m)-1){t=i;int num=t.count();if(num>n)continue;fo(k,0,m-1){if((!(i&(1<<k)))||(!(map[num][k+1])))continue;f[i]+=f[i-(1<<k)];}if(num==n)ans+=f[i];}cout<<ans<<endl;return 0;}
0 0
- poj2441 Arrange the Bulls 状压DP
- POJ2441 Arrange the Bulls 状态压缩DP
- Arrange the Bulls(poj2441)状态压缩dp
- POJ2441--Arrange the Bulls
- [poj2441]Arrange the Bulls
- [poj2441]Arrange the Bulls
- POJ2441-Arrange the Bulls
- POJ2441 2441 Arrange the Bulls
- poj 2441 Arrange the Bulls(状压DP)
- poj 2441 Arrange the Bulls (状压dp)
- POJ--2441--Arrange the Bulls--状压DP-滚动数组优化
- poj 2441 Arrange the Bulls(状压DP入门)
- poj 2441 Arrange the Bulls 状压dp入门
- poj 2441 Arrange the Bulls(状压dp)
- 文章标题 POJ 2441 :Arrange the Bulls(状压DP)
- 【pku2441】Arrange the Bulls
- Arrange the Bulls POJ
- POJ 2441 Arrange the Bulls && POJ 3254 Corn Fields 状压DP入门
- wincc 动态图片的集中实现办法
- 每一天都感觉自己在进步。
- linux 命令
- mac 安装使用Liteide
- NSRunLoop学习笔记
- poj2441 Arrange the Bulls 状压DP
- win7下vs2010的Visual Assist X插件过期后永久激活方法
- C# 汉字转拼音(支持GB2312字符集中所有汉字)
- ytu1402: 1.1.2 Greedy Gift Givers 贪婪的送礼者
- Hbase完全分布式配置
- springMVC 和 struts2区别
- iOS中根据已有经纬度定位并显示在地图上
- hdu 5635 LCP Array(BC第一题)
- ScrollView中ListView显示不全解决方法