题目链接:

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. PL/SQL编程—控制语句

      SQL> create or replace procedure sp_pro5(id_in varchar2) is v_sal mytest.salary%type; begin sel ...

  2. PAT 天梯赛 L1-008. 求整数段和 【水】

    题目链接 https://www.patest.cn/contests/gplt/L1-008 AC代码 #include <iostream> #include <cstdio&g ...

  3. Educational Codeforces Round 11A. Co-prime Array 数学

    地址:http://codeforces.com/contest/660/problem/A 题目: A. Co-prime Array time limit per test 1 second me ...

  4. HashMap的简单源码分析(看了大佬的源码,基于1.7) put方法

    参考博客: https://blog.csdn.net/eson_15/article/details/51158865 hashMap中的几个关键属性 //默认初始容量是16,必须是2的幂 stat ...

  5. PHP面向对象程序设计之抽象类和抽象方法

    抽象类: 抽象类不能被实例化.抽象类中只定义(或部分实现)子类需要的方法.子类可以继承它并且通过实现其中的抽象方法,使抽象类具体化. 我们可以用一个abstract关键字来定义一个抽象类,示例如下: ...

  6. VRChat简易教程4-使用VRC的接口实现物体的移动(VRC的action和trigger接口)

    这个教程我们学习如何实现载具的驾驶 一.准备工作 1 最简单的载具驾驶需要至少两个元素,一是需要一个载具,二是需要一个前进的按钮(这里我们只做前进功能),为了直观的能感受到载具的移动,我们还得创造一个 ...

  7. 20 个 OpenSSH 最佳安全实践

    来源:https://linux.cn/article-9394-1.html OpenSSH 是 SSH 协议的一个实现.一般通过 scp 或 sftp 用于远程登录.备份.远程文件传输等功能.SS ...

  8. mysql-8.0.11-winx64.zip安装教程

    mysql-8.0.11-winx64.zip安装教程   下载zip安装包: MySQL8.0 For Windows zip包下载地址:https://dev.mysql.com/download ...

  9. springBean的作用域

    Bean的作用域有五个类别 1.singleton,不写的话默认也是这个,这个的意思就是,单例的,就是说,不管你new多少次,都是一个对象 2.prototype,就是说每次new一个bean都是一个 ...

  10. Codeforces Round #365 (Div. 2) D.Mishka and Interesting sum 树状数组+离线

    D. Mishka and Interesting sum time limit per test 3.5 seconds memory limit per test 256 megabytes in ...