poj 2441 Arrange the Bulls
来源:互联网 发布:产品网络推广费用 编辑:程序博客网 时间:2024/05/22 16:53
题目:http://poj.org/problem?id=2441
简单状态dp,状态state中的1的个数表示安排了多少头牛,这些牛占了哪些房间//
/// dp[i][j] 枚举前i头牛,后状态为j的方案数LL dp[2][(1<<20)];vector<int>v[21];inline int getone(int st){ int ret=0; while(st) {ret++,st-=st&(-st);} return ret;}int main(){ int n,m,x,y; while(scanf("%d%d",&n,&m)!=EOF){ for(int i=0;i<=n;i++) v[i].clear(); memset(dp,0,sizeof(dp)); dp[0][0]=1; for(int i=1;i<=n;i++){ scanf("%d",&x); for(int j=0;j<x;j++) scanf("%d",&y),v[i].push_back(y-1); } for(int i=1;i<=n;i++){ for(int state=0;state<(1<<m);state++){ // 枚举所占的状态 if(getone(state)!=i) continue; for(int j=0;j<v[i].size();j++){ if(state&(1<<v[i][j])) dp[i&1][state]+=dp[1-(i&1)][state&(~(1<<v[i][j]))]; } } memset(dp[1-(i&1)],0,sizeof(dp[1-(i&1)])); } LL ans=0; for(int i=0;i<(1<<m);i++) ans+=dp[n&1][i]; printf("%lld\n",ans); } return 0;}
0 0
- POJ 2441 Arrange the Bulls
- poj 2441 Arrange the Bulls
- POJ-2441-Arrange the Bulls
- POJ 2441 Arrange the Bulls
- POJ 2441 Arrange the Bulls
- POJ 2441 Arrange the Bulls
- poj 2441 Arrange the Bulls
- Arrange the Bulls POJ
- poj 2441 Arrange the Bulls(状压DP)
- poj 2441 Arrange the Bulls (状压dp)
- POJ2441 2441 Arrange the Bulls
- POJ 2441 Arrange the Bulls(2007-06-07 13:08)
- poj 2441Arrange 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入门
- ArcGIS制图——单图层道路压盖处理
- POJ 2828 线段树
- INI文件操作
- Maven创建一个web应用
- char *p= "hello"和char p[] = "hello"的区别
- poj 2441 Arrange the Bulls
- oracle 中的视图
- Java中静态变量的适用场景
- Python: 使用zipfile+io模块在内存中进行zip操作
- SQL数据库质疑怎么解决呢?
- 如何在eclipse jee中创建Maven project并且转换为Dynamic web project
- 浅谈导航设计,开发者必备的十大实用技巧
- java文件或目录删除方法,列表删除易错点
- BNU 34974 MATLAB大法好