POJ 2436
来源:互联网 发布:beat制作软件 编辑:程序博客网 时间:2024/06/08 09:03
A 点击打开链接
#include<stdio.h>#include<string.h>#include<stack>#include<string>#include<math.h>#include<queue>#include<set>#include<algorithm>#include<iostream>#include<vector>#include<map>using namespace std;#define LL __int64#define inf 1999999999#define N 1010#define mod 1000000007/*状态压缩就是把所有状态用2进制的01表示,0表示没病,1表示有病要枚举的所有病的状态就要把每头牛得病的状态表示出来第一位从右看起,比如牛有第一种病就是000001,也就是1在比如牛有第一种和第二种病,也就是0000011,也就是3这样就把每头牛得病的状态表示出来了一共就15种病,所以用15位就可以表示出所有得病的状态,比如得15种病的状态就是11111111111111用10进制表示的数就是2^15*/int dp[N];bool judge(int x,int k){ int res=0; while(x) { res+=(x&1); x>>=1; } return res<=k;}int main(){ int i,j,m,n,k,num,x; while(scanf("%d%d%d",&n,&m,&k)!=-1) { memset(dp,0,sizeof(dp));//刚开始所有的牛都没有病 for(i=1;i<=n;i++) { scanf("%d",&num); while(num--) { scanf("%d",&x);//第i个牛得第x种病; dp[i]|=1<<(x-1);//加进去 } } int ans=0; for(i=0;i<(1<<m);i++) { if(judge(i,k)==0)//判断得病的种类不能超过k continue; int tmp=0;//在这种状态下牛得数量 for(j=1;j<=n;j++) { if((dp[j]&i)==dp[j]) tmp++; } ans=max(ans,tmp); } printf("%d\n",ans); } return 0;}
0 0
- POJ 2436
- POJ 2436
- POJ 2436 USACO silver
- POJ 2436 Disease Management
- POJ 2436 二进制枚举
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- POJ
- POJ
- iOS ---AFN--- 监测网络状态
- 出现 malformed or corrupted AST file: 'Unable to load module ".pcm": module file out of date'错误
- 【Android】 NFC课件
- php 文件操作类
- 连接池分析 pooling
- POJ 2436
- android----广播(BroadcastReceiver)的用法
- C# BackgroundWorker的使用
- 802.11n的HTC-MCS速率
- 给UIview加上xib
- 转一个 Xcode 7 缺少 *.dylib库的解决方法
- 密码学中的“盐值 Salt”
- 关于fseek不能定位大于2G文件的问题
- Apriori算法的R语言实现