题目链接:

Fluorescent

Time Limit: 3000/3000 MS (Java/Others)    

Memory Limit: 512000/512000 K (Java/Others)

Problem Description
Matt, a famous adventurer who once defeated a pack of dire wolves alone, found a lost court. Matt finds that there are N fluorescent lights which seem to be the stars from the firmament. What’s more, there are M switches that control these fluorescent lights. Each switch is connected to a group of lights. When Matt touches a switch, all the lights connected to it will change their states (turning the dark on, turning the bright off).

Initially, all the fluorescent lights are dark. For each switch, Matt will touch it with probability 1 .

As a curious gentleman, Matt wants to calculate E[X3], where X represents the number of bright lights at the end, E[X3] represents the expectation of cube of X.

 
Input
The first line contains only one integer T , which indicates the number of test cases.

For each test case, the first line contains N, M (1 ≤ N, M ≤ 50), denoting the number of fluorescent lights (numbered from 1 to N ) and the number of switches (numbered from 1 to M ).

M lines follow. The i-th line begins with an integer Ki (1 ≤ Ki ≤ N ). Ki distinct integers lij(1 ≤ lij ≤ N ) follow, denoting the fluorescent lights that the i-th switch controls.

 
Output
For each test case, output a single line “Case #x: y”, where x is the case number (starting from 1) and y is the answer. To avoid rounding error, the answer you should output is:

E[X3] × 2M mod (109 + 7)

 
Sample Input
 
2
2 2
1 1
2 1 2
3 1
3 1 2 3
 
Sample Output
 
Case #1: 10
Case #2: 27
 
题意:一些灯和一些开关,每个开关都能控制一部分灯,求在开关的所有状态亮灯个数立方和
 
思路:ans=sigma(x^3) ,把x^3拆开就是(x1+x2+...xn)*(x1+x2+...+xn)*(x1+x2+...+xn),ans=sigma(∑∑∑(xi*xj*xk))=∑∑∑(sigma(使得xixjxk同时亮的状态数))
这样可以避免枚举2^m个状态,因为只有三个灯亮,状态为2^3,所以复杂度约为O(n^3*m))
 
AC代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int n,m,a[51][51],k[50];
LL dp[51][8];
const LL mod=1e9+7;
LL solve(int u,int v,int w)
{
memset(dp,0,sizeof(dp));
dp[0][0]=1;
for(int i=1;i<=m;i++)
{
int tep=0;
for(int j=1;j<=k[i];j++)
{
if(a[i][j]==u)tep+=1;
if(a[i][j]==v)tep+=2;
if(a[i][j]==w)tep+=4;
}
for(int j=0;j<8;j++)dp[i][j]=dp[i-1][j];
for(int j=0;j<8;j++)dp[i][j^tep]+=dp[i-1][j],dp[i][j^tep]%=mod;
}
return dp[m][7]%mod;
}
int main()
{
int T,Case=0;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)
{
scanf("%d",&k[i]);
for(int j=1;j<=k[i];j++)scanf("%d",&a[i][j]);
}
LL ans=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
for(int k=1;k<=n;k++)
ans=ans+solve(i,j,k),ans%=mod;
printf("Case #%d: %lld\n",++Case,ans);
}
return 0;
}

  

hdu-5117 Fluorescent(状压dp)的更多相关文章

  1. HDU - 5117 Fluorescent(状压dp+思维)

    原题链接 题意 有N个灯和M个开关,每个开关控制着一些灯,如果按下某个开关,就会让对应的灯切换状态:问在每个开关按下与否的一共2^m情况下,每种状态下亮灯的个数的立方的和. 思路1.首先注意到N< ...

  2. HDU 4284Travel(状压DP)

    HDU 4284    Travel 有N个城市,M条边和H个这个人(PP)必须要去的城市,在每个城市里他都必须要“打工”,打工需要花费Di,可以挣到Ci,每条边有一个花费,现在求PP可不可以从起点1 ...

  3. HDU 4336 容斥原理 || 状压DP

    状压DP :F(S)=Sum*F(S)+p(x1)*F(S^(1<<x1))+p(x2)*F(S^(1<<x2))...+1; F(S)表示取状态为S的牌的期望次数,Sum表示 ...

  4. HDU 3001 Travelling ——状压DP

    [题目分析] 赤裸裸的状压DP. 每个点可以经过两次,问经过所有点的最短路径. 然后写了一发四进制(真是好写) 然后就MLE了. 懒得写hash了. 改成三进制,顺利A掉,时间垫底. [代码] #in ...

  5. hdu 4114(状压dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4114 思路:首先是floyd预处理出任意两点之间的最短距离.dp[state1][state2][u] ...

  6. HDU 3091 - Necklace - [状压DP]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3091 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...

  7. HDU 3811 Permutation 状压dp

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3811 Permutation Time Limit: 6000/3000 MS (Java/Othe ...

  8. HDU 5838 (状压DP+容斥)

    Problem Mountain 题目大意 给定一张n*m的地图,由 . 和 X 组成.要求给每个点一个1~n*m的数字(每个点不同),使得编号为X的点小于其周围的点,编号为.的点至少大于一个其周围的 ...

  9. hdu 4628 Pieces 状压dp

    题目链接 枚举所有状态, 1表示这个字符还在原来的串中, 0表示已经取出来了. 代码中j = (j+1)|i的用处是枚举所有包含i状态的状态. #include <iostream> #i ...

随机推荐

  1. svn / git SourceTree

    开发使用SourceTree 忽略文件这块老弄错,这次专门博客一下,使用CocoaPods 开发项目, 忽略步骤如下:  忽略文件内容如下 *.xcworkspace xcuserdata *.loc ...

  2. 解决You have new mail in /var/spool/mail/root提示

    终端远程登陆后经常提示You have new mail in /var/spool/mail/root 这个提示是LINUX会定时查看LINUX各种状态做汇总,每经过一段时间会把汇总的信息发送的ro ...

  3. Linux图形化界面下使用命令进行截图的方法

    以前在LINUX里面截图都是直接按print screen键或者 alt + print screen. 但是print screen是整个屏幕, alt + print screen是当前窗口. 想 ...

  4. 使用John the ripper工具来尝试破解Linux密码

    这篇文章主要介绍了使用John the ripper工具来尝试破解Linux密码的方法,这款工具可能主要被用来破解系统用户的密码以获得文件操作权限,需要的朋友可以参考下 John有别于Hdra之类的工 ...

  5. zabbix 邮件报警

    一.设置sendmail 安装sendmail yum install -y sendmail systemctl start sendmail.service 配置 cd  /usr/lib/zab ...

  6. LeetCode——Word Break

    Question Given a string s and a dictionary of words dict, determine if s can be segmented into a spa ...

  7. spring的cglib代理

    1.被代理类Person.java package com.xiaostudy; /** * @desc 被代理类 * * @author xiaostudy * */ public class Pe ...

  8. Hibernate -- 一对一映射

    一对一关联指两个表之间的记录是一一对应的关系.分为两种:外键关联和主键关联. (1)外键关联 比如一家公司(Company)和它所在的地址(Address).在业务逻辑中要求一家公司只有唯一的地址,一 ...

  9. XML DOM解析 基础概念

    DOM和SAX W3C制定了一套书写XML分析器的标准接口规范——DOM. 除此以外,XML_DEV邮件列表中的成员根据应用的需求也自发地定义了一套对XML文档进行操作的接口规范——SAX. 这两种接 ...

  10. docker 跨主机网络:overlay 简介

    简介 docker 在早前的时候没有考虑跨主机的容器通信,这个特性直到 docker 1.9 才出现.在此之前,如果希望位于不同主机的容器能够通信,一般有几种方法: 使用端口映射:直接把容器的服务端口 ...