poj 2441 Arrange the Bulls
来源:互联网 发布:ip地址和域名限制 编辑:程序博客网 时间:2024/06/11 07:13
状态压缩+DP+滚动数组
提交传送门
这道题主要就是理解
if((x&d[j])==0){ f[st][x+d[j]]+=f[1-st][x];}
这是Dp核心部分
#include<cmath>#include<cstdio>#include<cstring>#include<cstdlib>#include<sstream>#include<iostream>#include<algorithm>using namespace std;int n,m,f[3][1100000],a[110][110],d[110];int main(){ d[1]=1;for(int i=2;i<=20;i++)d[i]=(d[i-1]<<1); scanf("%d%d",&n,&m); for(int i=1;i<=n;i++){ int k;scanf("%d",&k); for(int j=1;j<=k;j++){ int x;scanf("%d",&x); a[i][x]=1; } } int st=0; for(int i=1;i<=m;i++)if(a[1][i]==1)f[st][d[i]]=1; int maxx=(1<<m)-1; for(int i=2;i<=n;i++){ st=1-st;memset(f[st],0,sizeof(f[st])); for(int j=1;j<=m;j++){ if(a[i][j]==1){ for(int x=0;x<=maxx;x++){ if(f[1-st][x]>0){ if((x&d[j])==0){ f[st][x+d[j]]+=f[1-st][x]; } } } } } } int ans=0; for(int x=1;x<=maxx;x++)ans+=f[st][x]; printf("%d\n",ans);}
大家赶快Ak吧QaQ
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入门
- java16进制字符串与字符串互相转换
- android多线程机制
- 纯真地看待生活
- [hihocoder #1127 : 二分图三·二分图最小点覆盖和最大独立集]
- 【最短路】BAPC2014 B Button Bashing (Codeforces GYM 100526)
- poj 2441 Arrange the Bulls
- ffmpeg综合应用示例(二)——为直播流添加特效
- 面向连接编程思想
- iOS获取通知状态并跳转设置界面设置
- kafka数据导入hbase
- TNS-01106:Listener using listener name already been started
- javascript高级程序设计读书笔记———创建对象
- Spark知识体系完整解读
- Android 动态设置布局属性